Etienne Low-Décarie
Etienne Low-Décarie

Reputation: 13443

Rotate a ggplot2 plot object

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.

Upvotes: 10

Views: 11415

Answers (2)

ialm
ialm

Reputation: 8717

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

Upvotes: 2

baptiste
baptiste

Reputation: 77096

print(p, vp=viewport(angle=-90))

Upvotes: 19

Related Questions