【发布时间】:2020-07-05 15:14:40
【问题描述】:
使用以下代码,我创建了 4 个箱线图:
bxp1<-ggplot(setTxy,aes(x=VolumCat2, y =perc_DVHT_99, fill=displ),position=position_dodge(width=5)) +
geom_boxplot() +
scale_x_discrete(labels = My.labels)+
scale_fill_manual(values=c("#999999","#E69F00","#56B4E9"))+
labs(title="Translation x-,y-direction",y="Ratio",ymin=0.5, ymax=1.2)
bxp3<-ggplot(setTz,aes(x=VolumCat2, y =perc_DVHT_99, fill=displ),position=position_dodge(width=5)) +
geom_boxplot() +
scale_x_discrete(labels = My.labels)+
scale_fill_manual(values=c("#999999","#E69F00","#56B4E9"))+
labs(title="Translation z-direction", x="Volume category",y="Ratio",ymin=0.5, ymax=1.2)
bxp2<- ggplot(setTxy,aes(x=VolumCat2, y =perc_DVHR_99, fill=displ),position=position_dodge(width=5)) +
geom_boxplot() +
scale_x_discrete(labels = My.labels)+
scale_fill_manual(values=c("#999999","#E69F00","#56B4E9"),name="Displacement")+
labs(title="Rotation x-,y-direction", y="Ratio",ymin=0.5, ymax=1.2)
bxp4<- ggplot(setTz,aes(x=VolumCat2, y =perc_DVHR_99, fill=displ),position=position_dodge(width=5)) +
geom_boxplot() +
scale_x_discrete(labels = My.labels)+
scale_fill_manual(values=c("#999999","#E69F00","#56B4E9"),name="Displacement")+
labs(title="Rotation z-direction", x="Volume category",y="Ratio",ymin=0.5, ymax=1.2)
figure<- ggarrange(bxp1,bxp2,bxp3,bxp4,
labels=c("a","b","c","d"),
ncol=2,nrow=2)
annotate_figure(figure,
top=text_grob("Ratio D99",color="black",face="bold",size=12),
fig.lab="Figure 1" )
但是如何进行以下更改: 1)对于前两个箱线图,我想松开 x 标签 2)对于所有的情节,我希望有相同的 y 轴间距 3)对于左边的两个箱线图,我想放开对名为 displ 的“箱”的解释 如果可能的话,我想为所有地块放开这个,只在 4 个箱线图的顶部添加灰色代表 0.5 毫米,橙色代表 1.0 毫米,蓝色代表 1.5 毫米位移
欢迎提出其他使此图看起来更好的建议
My.labels<-c("0-1cc\nn=39","1-5cc\nn=25","5-10cc\nn= 15","10-15cc\nn=6","15-20cc\nn=4",">20cc\nn=42")
dput() 给出:
setTxy 是一个长结构,看起来像:
structure(list(displ = c("0,5 mm", "0,5 mm", "0,5 mm", "0,5 mm",
"0,5 mm", "0,5 mm", "0,5 mm", "0,5 mm", "0,5 mm", "0,5 mm"),
perc_DVHT_99 = c(0.99169574073565, 0.983998642978761,
0.993452539098338, 0.983301531618343, 0.978633859305831,
0.97572227542085, 0.993287258697977, 0.993033293087417, 0.95287598273786,
0.970386976259169),
perc_DVHR_99 = c(0.998593284244034, 0.999335925776935,
0.996706003069954, 1.00115102497025, 0.96614985358813, 1.01255533813509,
1.00579263638508, 0.989133602564636, 0.955562258557279, 0.973325763729247),
perc_covT = c(0.996966632962588, 0.993933265925177, 0.997977755308392,
0.993933265925177, 0.99388379204893, 0.988786952089704, 0.99592252803262,
0.99592252803262, 0.992957746478873, 0.994969818913481),
perc_covR = c(0.998988877654196, 0.998988877654196, 0.998988877654196,
1, 0.986748216106014, 1.00509683995923, 1.00203873598369,
0.994903160040775, 0.992957746478873, 0.995975855130785),
VolumCat2 = c("e", "e", "e", "e", "b1", "b1", "b1", "b1",
"b1", "b1")), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))
在前十行中,仅显示“0.5mm”,但“1.0 mm”和“1.5 mm”的显示格式相同,但行号不同
setTz 结构相同
【问题讨论】:
-
请
dput()您的数据。这个问题是不可重现的。