以下是一种情况:
group1 <- seq(1, 10, 2)
group2 <- seq(1, 20, 3)
x = c(group1, group2)
mydf <- data.frame (X =x , Y = rnorm (length (x),5,1),
groups = c(rep(1, length (group1)), rep(2, length(group2))))
ggplot(mydf, aes(X, Y, group= groups)) + geom_point()+ facet_grid (.~ group)
在下图中,x个限制按比例缩放不同的面:
ggplot(mydf, aes(X, Y, group= groups)) + geom_point()+
facet_grid (.~ group, scales = "free_x")
由于x的总宽度有意义,我想生成不同宽度的小平面,不仅规模不同。因此,预期的方面1的宽度应该是2的一半。
答案 0 :(得分:46)
如果我理解正确,space = "free_x"
会做你想要的。
library(ggplot2)
ggplot(mydf, aes(X, Y)) + geom_point()+
facet_grid (.~ groups, scales = "free_x", space = "free_x")
如果你想在x轴上采用相同的标记方式:
ggplot(mydf, aes(X, Y)) + geom_point()+
scale_x_continuous(breaks = seq(0,20,2)) +
facet_grid (.~ groups, scales = "free_x", space = "free_x")