![](/img/trans.png)
[英]Boxplot comparison of multiple dataset using facet_wrap functionality of ggplot2 in R?
[英]ggplot2 boxplot facet wrap
我試圖在R中使用ggplot2在不同的面板或構面中構造具有不同參數集的箱形圖。 在輸入數據表中,我有一個“過程”列,其中包含參數分組。 但是,當我使用facet_wrap進行繪制時,即使大多數參數都沒有數據,即使使用drop = T,也將為每個構面顯示所有參數。
以下是我的代碼,任何建議都將非常有幫助!
ggplot(stRep, aes(x=Parameter, y=value, fill=Disease), facets=process) +
geom_boxplot(outlier.shape=NA) +
ylab("Posterior distribution") +
xlab("Parameter") + theme_bw() +
scale_fill_grey() + coord_flip() +
ylim(-6, 10) +
facet_wrap( ~ process, drop=T, ncol=1)
附帶的是數據的子集:
> test[c(1:5, 39995:40005),]
value Parameter Disease process
5001 -4.52611948 initial probability tree General parameters
5002 6.73178928 pers.intercept tree Persistence
5003 6.00318901 pers.intercept tree Persistence
5004 -4.05923658 pers. nei. effect tree Persistence
5005 0.05733596 pers. nei. effect tree Persistence
39995 -0.10238927 col. tick effect corn Initial colonization
39996 -0.12752092 col. tick effect corn Initial colonization
39997 -0.17067746 col. tick effect corn Initial colonization
39998 -0.06580708 col. tick effect corn Initial colonization
39999 -0.13382417 col. tick effect corn Initial colonization
40000 -0.12990795 col. tick effect corn Initial colonization
40001 0.22196724 col. Lyme effect corn Initial colonization
40002 0.24598469 col. Lyme effect corn Initial colonization
40003 0.26436187 col. Lyme effect corn Initial colonization
40004 0.23429840 col. Lyme effect corn Initial colonization
40005 0.22931861 col. Lyme effect corn Initial colonization
如果發布一些數據,測試各種選項會更容易。
但是,聽起來您應該在繪制之前將數據子集化:
stRep_no0s <- subset(stRep, value>0)
然后按照選項scales="free_x"
建議,使用scales="free_x"
選項代替drop=T
進行繪圖:
ggplot(stRep_no0s, aes(x=Parameter, y=value, fill=Disease), facets=process) +
geom_boxplot(outlier.shape=NA) +
ylab("Posterior distribution") +
xlab("Parameter") + theme_bw() +
scale_fill_grey() + coord_flip() +
ylim(-6, 10) +
facet_wrap( ~ process, scales="free_x", ncol=1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.