Y axis won't start at 0 in ggplot

后端 未结 2 1778
清酒与你
清酒与你 2020-12-11 03:15

In this plot I order the ylim to be 0, but the y axis seems to start at -1 anyway, which is very annoying. I really like the y axis to stat at 0. Solutions?

         


        
相关标签:
2条回答
  • 2020-12-11 03:56

    ggplot automatically extends the axes slightly to make sure there is room for points to plot. You can turn this behaviour off with the expand argument

    ggplot(sub1, aes(x=YR,y=Freq)) + 
      geom_bar(stat='identity') + 
      annotate("text",x=3,y=14.9,label="Population status",cex=10) +
      scale_y_continuous(expand = c(0, 0), limits = c(0, 15))
    
    0 讨论(0)
  • 2020-12-11 04:02
    p + scale_y_continuous(
      limits =   c(0,max_num),
      expand = expansion(mult = c(0,0.05))
    )
    

    this function ( expansion(mult = c(0,0.05))) may help

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