geom_text position middle on a bar plot

前端 未结 1 1889
一向
一向 2021-01-01 07:22

Need help with the aligning of the labels on the barplot.

Here is the reproducible code:

library(ggmap)
library(ggplot2)
library(gganimate)
library(r         


        
相关标签:
1条回答
  • 2021-01-01 08:12

    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()
    

    0 讨论(0)
提交回复
热议问题