在以下示例中,如何根据每个面板中的数据获取y轴限制?
mt <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point()
Run Code Online (Sandbox Code Playgroud)
这些都不会这样做:
mt + facet_grid(. ~ cyl, scales="free")
mt + facet_grid(. ~ cyl, scales="free_y")
Run Code Online (Sandbox Code Playgroud)
teu*_*and 51
我很抱歉突然提出这个 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")
Run Code Online (Sandbox Code Playgroud)

由reprex 包(v2.0.1)于 2022-06-09 创建
(免责声明:我是 ggh4x 的作者)
Geo*_*tas 48
也许是因为你只有一个y轴,用你的方式.你尝试过这样的事吗?
mt + facet_grid(cyl ~ ., scales="free")
Run Code Online (Sandbox Code Playgroud)