ggplot2——自动放大geom_smooth(使用coord_cartesian)
geom_smooth
很棒,很大程度上是因为它平均了很多变化。然而,正因为如此,当它缩小时,很难看出它在 x 轴上的变化。我正在生成大约 1000 个图表,我需要通过 coord_cartesian
放大 ggplot2
。然而,每个图表都有不同的缩放限制。有没有办法让 ggplot2 放大以适应平滑?我对仅放大 geom_smooth
线和 geom_smooth
线加 SE 阴影区域的解决方案感兴趣。
例如,我有兴趣知道如何将这个:
ggplot(data=mtcars, aes(y=qsec,x=wt)) + geom_point() + geom_smooth()
变成这样的:
ggplot(data=mtcars, aes(y=qsec,x=wt)) + geom_point() + geom_smooth() + coord_cartesian(ylim = c(15,20))
而不明确指定限制。
geom_smooth
is great, in large part because it averages out a lot of variation. However, because of this, it's difficult to see how it varies over the x-axis when it is zoomed out. I am producing about 1000 graphs where I need to have ggplot2
zoom in via coord_cartesian
. However, each graph would have different zoom limits. Is there a way I can ask ggplot2
to zoom in to fit the smooth? I am interested in solutions for both zooming in on just the geom_smooth
line and the geom_smooth
line plus SE shaded area.
For example, I would be interested in knowing how I could turn this:
ggplot(data=mtcars, aes(y=qsec,x=wt)) + geom_point() + geom_smooth()
into something like this:
ggplot(data=mtcars, aes(y=qsec,x=wt)) + geom_point() + geom_smooth() + coord_cartesian(ylim = c(15,20))
without explicitly specifying the limits.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
手动拟合平滑模型可以让您更加灵活地实现这种自定义和其他类型的自定义。对于大多数项目,我一开始使用内联界面,但当我需要其他调整时,通常最终不得不切换到手动计算。
另请参阅 Hadley 书中的 §9.1.1。
但是,这仍然不适用于构面,因为您只能指定,例如
scales='free'
,而不是直接的实际限制。Fitting your smoothing models manually gives you much more flexibility for attaining this and other types of customization. For most projects, I start off using the in-line interface, but then usually end up having to switch to manual calculation when I need other tweaks.
See also §9.1.1 in Hadley's book.
However, this still doesn't work for facets because you can only specify, for example,
scales='free'
, and not the actual limits directly.