ggplot2、facet_grid、自由尺度?
在下面的示例中,如何根据每个面板中的数据来缩放 y 轴限制?
mt <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point()
这些都不会做到这一点:
mt + facet_grid(. ~ cyl, scales="free")
mt + facet_grid(. ~ cyl, scales="free_y")
In the following example, how do I get the y-axis limits to scale according to the data in each panel?
mt <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point()
Neither of these will do it:
mt + facet_grid(. ~ cyl, scales="free")
mt + facet_grid(. ~ cyl, scales="free_y")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试: https://teunbrand.github.io/ggh4x/reference/facet_grid2.html< /a>.
此代码允许使用facet_grid(但使用facet_grid2)使每个面板的比例独立。
Try: https://teunbrand.github.io/ggh4x/reference/facet_grid2.html.
This code allows to make the scales of each panel independent using facet_grid, but with facet_grid2.
也许是因为你只有一个 y 轴,用你的方式。你尝试过这样的事情吗?
Perhaps it's because you have only one y axis, using your way. Did you try something like this?
我很抱歉突然提出这个 12 年前的问题并给出了新答案,但我认为它可能有用。如果您想保留网格布局,但想要像环绕一样的自由刻度,您可能会对
ggh4x::facet_grid2()
感兴趣,它有一个independent
参数,可以让轴在网格布局中的行或列内变化。由 reprex 包 (v2.0.1)
(免责声明:我是 ggh4x 的作者)
I'm sorry for jumping on this 12 year old question with a new answer, but I think it might be useful. If you want to preserve the grid layout, but want wrap-like free scales, you might be interested in
ggh4x::facet_grid2()
which has anindependent
argument that lets an axis vary within a row or column in a grid-layout.Created on 2022-06-09 by the reprex package (v2.0.1)
(Disclaimer: I'm the author of ggh4x)
你不能。请参阅此处
您可以使用
facet_wrap
代替,它将“免费” ' 两个轴You can't. See here
You can use
facet_wrap
instead, which will 'free' both axes希望这会有所帮助。
Hopefully, this helps.