我想有刻面的箱线图图像上自由尺度。
使用这个例子中的数据集,如果我试试这个:
ggplot(data=mpg) +
geom_boxplot(aes(x=cty, y=model))+
facet_grid(manufacturer ~ drv, scales = "free", space = "free")
情节不正确箱线图http://dl.dropbox.com/u/9788680/plot1.png
在这里,自由尺度实作,我想,与这取决于可用的因素的水平方面的规则数y轴的不同尺度。 箱图被然而不能正确描绘(即,作为实线,而不是箱图)。 当一个解决方案搜索,我发现我应该使用coord_flip()为了使箱线图来描绘正确,即
ggplot(data=mpg) +
geom_boxplot(aes(x=model,y=cty))+
facet_grid(manufacturer ~ drv, scales = "free", space = "free")+
coord_flip()
情节正确的箱线图,但不结垢http://dl.dropbox.com/u/9788680/plot2.png
在上面的图片中,箱线图现在是正确的。 然而,对于要素自由刻度(以便在y轴)被除去。 现在,对于每个水平面线,ALL跨越数据集的可用因素现在被包括,而不是只适用于每个小面的因素(如在图1)。
我想知道我怎么能得到正确的磨制与无标两轴,正确地描绘箱线图。
如果有人能在正确的方向指向我,我将不胜感激。
谢谢。
期望的行为至少被支持为GGPLOT2 2.2.1。
library(ggplot2)
ggplot(data=mpg[which(mpg$manufacturer %in% c('audi', 'hyundai', 'jeep')),]) +
geom_boxplot(aes(x=model,y=cty)) +
facet_grid(manufacturer ~ drv, scales = "free", space = "free") +
coord_flip()
sessionInfo()
#> R version 3.3.2 (2016-10-31)
#> Platform: x86_64-apple-darwin13.4.0 (64-bit)
#> Running under: OS X El Capitan 10.11.6
#>
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] ggplot2_2.2.1
#>
#> loaded via a namespace (and not attached):
#> [1] Rcpp_0.12.11 digest_0.6.12 rprojroot_1.2
#> [4] plyr_1.8.4 grid_3.3.2 gtable_0.2.0
#> [7] backports_1.0.5 magrittr_1.5 evaluate_0.10.1
#> [10] scales_0.4.1.9002 rlang_0.1.1.9000 stringi_1.1.5
#> [13] reshape2_1.4.2 lazyeval_0.2.0 rmarkdown_1.6.0.9001
#> [16] labeling_0.3 tools_3.3.2 stringr_1.2.0
#> [19] munsell_0.4.3 yaml_2.1.14 colorspace_1.3-2
#> [22] htmltools_0.3.6 knitr_1.16 tibble_1.3.3
我昨天注意到独立于该水平bxoplots显示为线 - 我还不确定它是否是一个错误,或功能,或是其CA被改变
你的情况,我这样做
library(ggplot2)
ggplot(data=mpg) +
geom_boxplot(aes(y=cty, x=model,fill=model))+
facet_grid(manufacturer~drv, scales = "free", space = "free")+theme(axis.text.x=element_text(angle=90),legend.position="none")
刚好对调x和y,并刻面= _grid号召,加入了一些色彩和旋转的X标志 - 我想这是你想要的只是翻转