【发布时间】:2020-12-13 22:46:28
【问题描述】:
您能否帮我将中间 IQR 标签添加到由 facet_wrap 生成的面板的 x 轴。恐怕我无法复制以前的 SO 建议。我附上了我的代码和示例输出。谢谢。
#data
>head(df.tnbc,10)
# A tibble: 10 x 3
variable.x value.x value.y
<fct> <dbl> <fct>
1 Tumor_Fraction_ULPS 24.2 TNBC/basal (ER-/PR-/HER2-) +
2 Tumor_Fraction_30xWGS 24.3 TNBC/basal (ER-/PR-/HER2-) +
3 Tumor_Fraction_ULPS 13.2 TNBC/basal (ER-/PR-/HER2-) +
4 Tumor_Fraction_30xWGS 14.5 TNBC/basal (ER-/PR-/HER2-) +
5 Tumor_Fraction_ULPS 12.3 TNBC/basal (ER-/PR-/HER2-) +
6 Tumor_Fraction_30xWGS 11.7 TNBC/basal (ER-/PR-/HER2-) +
7 Tumor_Fraction_30xWGS 8.66 Non-TNBC/basal (ER-/PR-/HER2-)
8 Tumor_Fraction_ULPS 9.38 Non-TNBC/basal (ER-/PR-/HER2-)
9 Tumor_Fraction_ULPS 6.57 Non-TNBC/basal (ER-/PR-/HER2-)
10 Tumor_Fraction_30xWGS 7.61 Non-TNBC/basal (ER-/PR-/HER2-)
#code I tried
ggplot(data=df.tnbc ,aes(x=factor(value.y), y=value.x),color=value.x) +
geom_boxplot(outlier.size = 0,fill="darkgoldenrod2")+geom_jitter(shape=16, size=2,height=0)+
xlab("TNBC status by Immunohistochemistry staining") + ylab("ctDNA fractions / %")+scale_y_continuous(limits = c(0,25))+
ggtitle("ctDNA fractions by TNBC status") +
theme(plot.title=element_text(family="Times", face="bold", size=14,hjust = 1),
axis.text.x = element_text(family="Times", angle = 45, hjust = 1, face="bold"),
axis.text.y = element_text(family="Times", size = 14, face="bold"),
axis.title.y = element_text(family="Times", size = 14, face="bold"),
axis.title.x = element_text(family="Times", size = 14, face="bold"),
legend.title = element_text(family="Times",color = "black", size = 14, face="bold"),
legend.text = element_text(family="Times",color = "black", face="bold"))+stat_compare_means(na.rm=TRUE,label.x=3,hjust = 2.9)+
theme_pubclean() +
facet_wrap(~variable.x, scale="free")
##editing individual x- axis to append median IQR fails
ggplot(data=df.tnbc ,aes(x=factor(value.y), y=value.x),color=value.x) +
geom_boxplot(outlier.size = 0,fill="darkgoldenrod2")+geom_jitter(shape=16, size=2,height=0)+
xlab("TNBC status by Immunohistochemistry staining") + ylab("ctDNA fractions / %")+scale_y_continuous(limits = c(0,25))+
ggtitle("ctDNA fractions by TNBC status") +
theme(plot.title=element_text(family="Times", face="bold", size=14,hjust = 1),
axis.text.x = element_text(family="Times", angle = 45, hjust = 1, face="bold"),
axis.text.y = element_text(family="Times", size = 14, face="bold"),
axis.title.y = element_text(family="Times", size = 14, face="bold"),
axis.title.x = element_text(family="Times", size = 14, face="bold"),
legend.title = element_text(family="Times",color = "black", size = 14, face="bold"),
legend.text = element_text(family="Times",color = "black", face="bold"))+stat_compare_means(na.rm=TRUE,label.x=3,hjust = 2.9)+
theme_pubclean() +
facet_wrap(~variable.x, scale="free",
labeller = labeller(variable.x = c("Tumor_Fraction_ULPS","Tumor_Fraction_30xWGS"),
value.y = c("Non-TNBC/basal Med[IQR] 4.76% [1.12%-5.84%]","TNBC/basal (ER-/PR-/HER2-) Med[IQR] 12.8% [10.1%-15.9%]",
"Non-TNBC/basal Med[IQR] 3.08% [2.12%-6.33%]","TNBC/basal (ER-/PR-/HER2-) Med[IQR] 13.1% [9.41%-17.0%]")))
【问题讨论】:
-
你要修改什么?在轴上添加一些文本?
-
是的,将文本(中值 IQR 值)添加到 x 轴
-
下面的框,对吧?
-
@Duck 是的,在方框下面。
-
您能否使用
dput(head(df.tnbc,100))添加一些数据,编辑您的问题并粘贴输出以重现您的代码?
标签: r ggplot2 facet-wrap