Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: ggplot2 - switch argument doesn't work as expected

Tags:

r

ggplot2

this is rather a simple question.

According with: http://docs.ggplot2.org/current/facet_grid.html

Note: I've tried with CRAN and Github version of Ggplot2.

With this code, I should expect this graph:

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")

Graph:

enter image description here

But I'm getting a similar graph, where the "strip text" is not behind the "y axi" but before the axi:

enter image description here

My 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 
like image 388
Omar Gonzales Avatar asked Jul 26 '26 08:07

Omar Gonzales


1 Answers

+ theme(strip.placement = "outside")
like image 170
baptiste Avatar answered Jul 28 '26 21:07

baptiste



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!