Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate a ggplot2 plot object

Tags:

plot

r

ggplot2

I would like to rotate a complete ggplot object 90°.

I do not wish to use coord_flip as this appears to interfere with scale="free" and space="free" when using facets.

For example:

qplot(as.factor(mpg), wt, data=mtcars)+
facet_grid(.~vs + am, scale="free",space="free")

enter image description here

vs

qplot(as.factor(mpg), wt, data=mtcars)+
  facet_grid(vs + am ~ ., scale="free",space="free")+
  coord_flip()

enter image description here

What I would like:

enter image description here

I would likely need to use gridExtra.

like image 808
Etienne Low-Décarie Avatar asked Jun 19 '14 17:06

Etienne Low-Décarie


Video Answer


2 Answers

Is this what you were expecting?

qplot(x=wt, y=as.factor(mpg), data=mtcars) +
  facet_grid(vs + am ~ ., scale="free", space="free")

"rotated" plot

like image 54
ialm Avatar answered Sep 22 '22 09:09

ialm


print(p, vp=viewport(angle=-90))
like image 26
baptiste Avatar answered Sep 22 '22 09:09

baptiste