比例=“免费"适用于facet_wrap但不适用于facet_grid [英] Scales = "free" works for facet_wrap but doesn't for facet_grid
问题描述
我试图理解为什么facet_grid()
和facet_wrap()
的输出不同,即使输入相同:
I'm trying to understand why the outputs of facet_grid()
and facet_wrap()
are different, even though the inputs are the same:
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()
具有不同的行为.有什么可以解释的?
See, the argument scales = "free"
does not have the same behaviors for facet_grid()
and facet_wrap()
. What can explain that?
推荐答案
引用此链接:
facet_grid
用一个或两个在水平和/或垂直方向上变化的变量将数据划分为多个方面,而facet_wrap
将这些方面彼此相邻,并包裹一定数量的列或行.换句话说,facet_wrap
仅具有水平尺寸.
facet_grid
split the data into facets by one or two variables that vary on the horizontal and/or vertical direction, while facet_wrap
places the facets next to each other, wrapping with a certain number of columns or rows. In other words, facet_wrap
only has horizontal dimension.
因此,使用该链接中的示例,sp + facet_grid(. ~ sex)
的行为与sp + facet_grid( ~ sex)
相同.就您而言,facet_grid(. ~ referencia)
和facet_wrap( ~ referencia)
应该产生相同的图.
Therefore, using the example from that link, sp + facet_grid(. ~ sex)
would behave the same as sp + facet_grid( ~ sex)
. In your case, facet_grid(. ~ referencia)
and facet_wrap( ~ referencia)
should produce the same plot.
对于二维面或更多的二维面,facet_grid
根据参数(vertical ~ horizontal)
生成图的网格.另一方面,facet_wrap
只会水平堆叠图.然后,用户可以通过指定列数或行数来设置布局.
For two or more dimensional facets, facet_grid
produces a grid of plots based on the parameter (vertical ~ horizontal)
. facet_wrap
, on the other hand, would just stack the plots horizontally. User then can set the layout by specifying the number of columns or rows.
现在,当添加scales = "free"
自变量时,facet_grid
中的构面仍将受到网格的限制,因此同一行上的图不能具有不同的y轴.同样,每列只能有一个x轴.不过,使用facet_wrap
可以独立显示每个图,因此可以释放"其x轴和y轴.
Now, when the scales = "free"
argument is added, facets in facet_grid
would still be bounded by the grid, therefore plots on the same row cannot have different y-axis. Similarly, there can only single x-axis for each column. Using facet_wrap
though, each plot is displayed independently, so it can "free" its x-axis and y-axis.
在我看来,当您想相对比较类别中的图时,facet_grid
很有用,这可以通过设置相同的轴比例来实现.同时,facet_wrap
对于彼此之间更加独立的图更为有用.
In my opinion, facet_grid
is useful when you want to relatively compare the plots within a category, which can be accomplished by setting the same axis scales. Meanwhile, facet_wrap
is more useful for plots that more independent between one another.
这篇关于比例=“免费"适用于facet_wrap但不适用于facet_grid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!