require(ggplot2)
x = c(rnorm(30,3,3),rnorm(30,3,3),rnorm(30,1.5,0.2),rnorm(30,1.5,5))
y = x + rnorm(length(x))
d = data.frame(x=x, y=y, Country = rep(c("Australia", "Iran"),each=60), Environment = rep(rep(c("Forest", "Desert"),each=30),2))
ggplot(d,aes(x=x,y=y)) + geom_point() + facet_grid(.~Country+Environment)
我希望变量Country
(Australia
和Iran
)的两个可能值只在图表顶部写入两次,并且按顺序有更长的水平灰色条包含嵌套变量Environment
的两个可能值。这可行吗?
当然可以做一些事情,比如
ggplot(d,aes(x=x,y=y)) + geom_point() + facet_grid(Country~Environment)
或
ggplot(d,aes(x=x,y=y, colour=Environment)) + geom_point() + facet_grid(Country~.)
但这不是我想要实现的目标