繁体   English   中英

ggplot2,facet_grid,自由秤?

[英]ggplot2, facet_grid, free scales?

在以下示例中,如何根据每个面板中的数据来缩放 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")

也许是因为你只有一个 y 轴,用你的方式。 你尝试过这样的事情吗?

mt + facet_grid(cyl ~ ., scales="free")

你不能。 这里

您可以改用facet_wrap ,这将“释放”两个轴

希望这会有所帮助。

mt + facet_wrap(. ~ cyl, scales="free_y")

我很抱歉用一个新的答案来回答这个 12 岁的问题,但我认为它可能有用。 如果您想保留网格布局,但想要类似环绕的自由比例,您可能会对ggh4x::facet_grid2()感兴趣,它有一个independent的参数,可以让轴在网格布局中的行或列内变化。

library(ggplot2)

ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + 
  geom_point() +
  ggh4x::facet_grid2(. ~ cyl, scales = "free_y", independent = "y")

reprex 包(v2.0.1) 创建于 2022-06-09

(免责声明:我是ggh4x的作者)

试试: https ://teunbrand.github.io/ggh4x/reference/facet_grid2.html。

此代码允许使用 facet_grid 使每个面板的比例独立,但使用 facet_grid2。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM