首先,对不起我的英语和错误.我有这样的情节:
data <- data.frame(site=rep(letters[1:6],each=3), year=rep(2001:2003, 6), nb=round(runif(18, min=20, max=60)), group=c(rep("A",9),rep("B", 6),rep("C",3)))
ggplot(data=data, aes(x= factor(year), y= nb)) +
geom_point() +
facet_wrap(~site)
Run Code Online (Sandbox Code Playgroud)
我想添加其他面板"组".事实上,我想制作没有空白部分的图表:
ggplot(data=data, aes(x= factor(year), y= nb)) +
geom_point() +
facet_grid(group~site)
Run Code Online (Sandbox Code Playgroud)
有人有想法吗?谢谢你的帮助!
这个解决方案看起来像我想要的,但我认为有更简单的解决方案:
plt1 <- ggplot(data=data[data$group=="A",], aes(x= factor(year), y= nb)) +
geom_point() +
ggtitle("A")+
facet_grid(~site)+
xlab("") + ylab("")
plt2 <- ggplot(data=data[data$group=="B",], aes(x= factor(year), y= nb)) +
geom_point() +
ggtitle("B")+
facet_grid(~site)+
xlab("") + ylab("")
plt3 <- ggplot(data=data[data$group=="C",], aes(x= factor(year), y= nb)) +
geom_point() +
ggtitle("C")+
facet_grid(~site)+
xlab("") + ylab("")
library(gridExtra)
grid.arrange(arrangeGrob(plt1,plt2, plt3),
left = textGrob("nb",rot=90))
Run Code Online (Sandbox Code Playgroud)
你可以把它site和group里面结合起来facet_wrap()- 所以你只有"完整"的方面.
ggplot(data=data, aes(x= factor(year), y= nb)) +
geom_point() +
facet_wrap(~site+group)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1044 次 |
| 最近记录: |