geom_text position middle on a bar plot

我们两清 提交于 2019-11-30 16:45:10

With recent updates to ggplot2, you can do this by setting position = position_stack(vjust = 0.5) in geom_text().

It may also interest you that you can use geom_col() as a shortcut for geom_bar(stat = "identity"). Also, labs has a title and subtitle parameter, so you don't need to use it and ggtitle.

ggplot(data = mydf1, aes(x = year, y = channels, fill = type, frame = year, cumulative = TRUE)) +
  geom_col() +
  labs(x = "year", y = "y", title = "Data Here", subtitle = "Statistics") +
  geom_text(aes(label = channels), color = "white", size = 3, position = position_stack(vjust = 0.5)) + 
  theme_minimal()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!