2014-06-19 170 views
6

我想旋转一个完整的ggplot对象90°。旋转ggplot2图形对象

我不想使用coord_flip,因为这在使用构面时似乎会干扰scale="free"space="free"

例如:

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

我想什么:

enter image description here

我可能需要使用gridExtra

+0

为什么你需要与GGPLOT2 /格旋转?在你想要使用的任何软件(例如乳胶或单词)中旋转可能更容易。 – Roland

回答

13
print(p, vp=viewport(angle=-90)) 
+0

我发现的费力的选择是'grid.newpage() pushViewport(viewport(angle = -90,width = unit(7,“inches”),height = unit(7,“inches”))))grid.draw (ggplot_gtable(ggplot_build(p)))' –

+1

好的。你是网格王牌。 (我可能只是打印为“风景”,但是我可以看到能够使用knitr或其他标记系统发送该文件的价值。 –

+1

@ EtienneLow-Décarie如果您推送了视口,则可以使用print(p ,newpage = FALSE)'如果由于某种原因你想明确地绘制一个grob,'ggplotGrob'是一个较短的别名 – baptiste

1

这是你所期待的吗?

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

"rotated" plot

+0

是的,但是转动整个绘图就是我要找的。 –