0
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

I would like the two possible values of the variable Country (Australia and Iran) to be written only twice at the top of the graph and have longer horizontal grey bars in order to encompass the two possible values of the nested variable Environment. Is it feasible?


Of course one could do things like

ggplot(d,aes(x=x,y=y)) + geom_point() + facet_grid(Country~Environment)

or

ggplot(d,aes(x=x,y=y, colour=Environment)) + geom_point() + facet_grid(Country~.)

but it is not what I am trying to achieve

Remi.b
  • 17,389
  • 28
  • 87
  • 168

0 Answers0