R ggplot boxplot: change y-axis limit

后端 未结 1 1926
鱼传尺愫
鱼传尺愫 2020-12-15 22:55

I\'m using ggplot to create sevral boxplots from the following data:

df<-(structure(list(Effect2 = c(\"A2\", \"A2\", \"A2\", \"A2\", \"A2\",          


        
相关标签:
1条回答
  • 2020-12-15 23:37

    Use coord_cartesian instead of scale_y_continuous:

    ggplot(df, aes(x=Effect2, y=OddsRatioEst)) +
        geom_boxplot(outlier.colour=NA) + 
        coord_cartesian(ylim = c(0, 100))
    

    From the coord_cartesian documentation:

    Setting limits on the coordinate system will zoom the plot (like you're looking at it with a magnifying glass), and will not change the underlying data like setting limits on a scale will.

    The output is as follows. As you can see, not deleting those outliers changes the picture somewhat, so you may want to change the y limit as well. enter image description here

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