2014-06-19 171 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

是的,但是轉動整個繪圖就是我要找的。 –