使用ggplot2绘制小提琴图展示cancer和exp关系
这段代码使用了ggplot2包来绘制一个小提琴图,展示了数据集dataA中'cancer'和'exp'两个变量之间的关系。具体来说,每个'cancer'类别的'exp'值分布被绘制为一个小提琴形状,并用对应的颜色填充。除此之外,还添加了一个黑色点表示每个'cancer'类别的'exp'均值,并添加了两条水平虚线表示0.6和0.3两个参考值。图形被翻转以便更好地展示x轴变量,同时调整了颜色、字体等细节。最后,还添加了一个remove_y函数来移除y轴标签和刻度线。
p1 <-ggplot(dataA,aes(cancer,exp,fill=cancer))+
geom_violin()+
coord_flip()+
scale_fill_manual(values = colors)+
stat_summary(fun=mean,geom = "point",
shape = 19, size = 2, color = "black")+
theme_bw()+
geom_hline(aes(yintercept=0.6),colour="#565354",linetype="dashed")+
geom_hline(aes(yintercept=0.3),colour="#565354",linetype="dashed")+
xlab('')+
ylab('A indicator
indicator A')+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.y = element_text(size = 12,
face = "bold"),
legend.title = element_blank(),
legend.position = 'none')
p1
remove_y <- theme(
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.y = element_blank(),
)
原文地址: https://www.cveoy.top/t/topic/nJWC 著作权归作者所有。请勿转载和采集!