ggplot2:facet_grid中的嵌套变量

时间:2016-02-16 22:47:20

标签: r graph graphics ggplot2 facet

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)

enter image description here

我希望变量CountryAustraliaIran)的两个可能值只在图表顶部写入两次,并且按顺序有更长的水平灰色条包含嵌套变量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~.)

但这不是我想要实现的目标

0 个答案:

没有答案