![](/img/trans.png)
[英]Looking to solve problem with facet_wrap/facet_grid that isn't resolved with space = "free"
[英]Scales = “free” works for facet_wrap but doesn't for facet_grid
我试图了解为何facet_grid()
和facet_wrap()
的输出不同,即使输入相同:
ggplot(temp, aes(x = valor)) +
geom_histogram(binwidth = 5, fill = NA, color = "black") +
facet_grid(estratificacao ~ referencia, scales = "free") +
scale_x_continuous(breaks = seq(0, 100, 10)) + theme_classic()
ggplot(temp, aes(x = valor)) +
geom_histogram(binwidth = 5, fill = NA, color = "black") +
facet_wrap(estratificacao ~ referencia, scales = "free") +
scale_x_continuous(breaks = seq(0, 100, 10)) + theme_classic()
参见, scales = "free"
参数对于facet_grid()
和facet_wrap()
。 有什么可以解释的?
引用此链接 :
facet_grid
通过在水平和/或垂直方向上变化的一个或两个变量将数据划分为多个方面,而facet_wrap
这些方面彼此相邻,并包裹了一定数量的列或行。 换句话说, facet_wrap
仅具有水平尺寸。
因此,使用该链接中的示例, sp + facet_grid(. ~ sex)
行为与sp + facet_grid( ~ sex)
。 在您的情况下, facet_grid(. ~ referencia)
和facet_wrap( ~ referencia)
应该产生相同的图。
对于二维或更多个小平面, facet_grid
基于参数(vertical ~ horizontal)
生成一个网格图。 另一方面, facet_wrap
只会将绘图水平堆叠。 然后,用户可以通过指定列数或行数来设置布局。
现在,当添加scales = "free"
参数时, facet_grid
构面仍将受到网格的限制,因此同一行上的图不能具有不同的y轴。 同样,每列只能有一个x轴。 但是,使用facet_wrap
可以独立显示每个图,因此可以“释放”其x轴和y轴。
我认为,当您想相对比较类别中的图时, facet_grid
很有用,这可以通过设置相同的轴比例来实现。 同时, facet_wrap
对于彼此之间更加独立的图更为有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.