R ggplot boxplot: change y-axis limit

风格不统一 提交于 2019-12-04 02:48:35

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.

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