2017-03-11 45 views
3

這是一個相當簡單的問題。R:ggplot2 - 開關參數不能按預期工作

有根據:http://docs.ggplot2.org/current/facet_grid.html

注:我已經與GGPLOT2的CRAN和Github的版本嘗試。

有了這個代碼,我應該期待這個圖:

data <- transform(mtcars, 
       am = factor(am, levels = 0:1, c("Automatic", "Manual")), 
       gear = factor(gear, levels = 3:5, labels = c("Three", "Four", "Five")) 
) 


p <- ggplot(data, aes(mpg, disp)) + geom_point() 
p + facet_grid(am ~ gear, switch = "both") 

圖:

enter image description here

但我發現了一個類似的圖,其中 「帶文本」 是不是背後「axi」但在axi之前:

enter image description here

我sessionInfo():

> sessionInfo() 
R version 3.3.2 (2016-10-31) 
Platform: x86_64-w64-mingw32/x64 (64-bit) 
Running under: Windows 7 x64 (build 7601) Service Pack 1 

locale: 
[1] LC_COLLATE=Spanish_Peru.1252 
[2] LC_CTYPE=Spanish_Peru.1252 
[3] LC_MONETARY=Spanish_Peru.1252 
[4] LC_NUMERIC=C     
[5] LC_TIME=Spanish_Peru.1252  

attached base packages: 
[1] stats  graphics grDevices utils  datasets 
[6] methods base  

other attached packages: 
[1] dplyr_0.5.0  ggplot2_2.2.1.9000 

loaded via a namespace (and not attached): 
[1] Rcpp_0.12.9  assertthat_0.1 digest_0.6.12 
[4] withr_1.0.2  grid_3.3.2  R6_2.2.0   
[7] plyr_1.8.4  DBI_0.5-1  gtable_0.2.0  
[10] magrittr_1.5  git2r_0.16.0  scales_0.4.1  
[13] httr_1.2.1  stringi_1.1.2 reshape2_1.4.2 
[16] lazyeval_0.2.0 curl_2.3   labeling_0.3  
[19] devtools_1.12.0 tools_3.3.2  stringr_1.1.0 
[22] munsell_0.4.3 colorspace_1.3-1 memoise_1.0.0 
[25] knitr_1.15.1  tibble_1.2-15 

回答

6
+ theme(strip.placement = "outside") 
+0

謝謝你巴蒂斯特,所以文檔需要更新... –