![](/img/trans.png)
[英]Creating 2 panels and 2 hlines with facet_grid & ggplot2 in R
[英]ggplot2 facet_grid arrange panels
以下示例创建一个ggplot
,其中ggplot
包含4个面板“A”,“B”,“C”,“D”。
我想出了如何在一列中绘制这4个面板。 然而,仍然是一个谜仍然是如何安排4个面板,使“A”和“B”在第一行,“C”和“D”放在一个单独的(第二)行?
这是我的代码:
df <- data.frame(
x = rep(rep(1:10, each=10), 2),
y = rep(rep(1:10, 20), 2),
grid = rep(LETTERS[1:4], each=100)
)
ggplot(df, aes(x = x, y = y)) +
geom_point() +
facet_grid(. ~ grid, scales = "free")
使用facet_wrap
而不是facet_grid
:
library(ggplot2)
ggplot(df, aes(x = x, y = y)) +
geom_point(aes(colour=grid)) +
facet_wrap(~ grid, scales = "free")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.