Lollipop
写在前面
【这图怎么画】系列的图都来自VIP群
里同学的提问。推文只是对图片的复现,不代表作者对图片展现形式的认同。欢迎同学们在群里分享有意思的图片。
本期图片
相关分析棒棒糖图
❝Title:Integrated Analysis Identifies Four Genes as Novel Diagnostic Biomarkers Which Correlate with Immune Infiltration in Preeclampsia
❞
这是一个相关分析结果的展示图。这里作者分别用色阶条以及数值展现了pvalue,用点的大小表示相关系数绝对值。
复现结果
复现结果
❝稍微调整了一下,原图把p值分层好多段,尤其是>0.05的部分,我觉得意义不大。
❞
绘图
dat = read.csv("cor.csv") head(dat) # 对相关系数和p值转换为分类变量 dat$cor1 <- cut(abs(dat$cor),# 绝对值 breaks = c(0, 0.3, 0.5, 0.7, 0.9, 1), labels = c("< 0.3","0.3 - 0.5","0.5 - 0.7","0.7 - 0.9","> 0.9"), right=FALSE) # right=FALSE表示表示区间为左闭右开 dat$pvalue1 <- cut(dat$pvalue, breaks = c(0, 0.001, 0.01, 0.05, 1), labels = c("< 0.001","< 0.01","< 0.05","> 0.05"), right=FALSE) # 排序 dat = dat[order(dat$cor),] dat$Cell = factor(dat$Cell, levels = dat$Cell) p = ggplot(dat, aes(x = cor, y = Cell, color = pvalue1)) + scale_color_manual(name="pvalue", values = c("#E69F00", "#56B4E9", "#009E73", "gray"))+ geom_segment(aes(x = 0, y = Cell, xend = cor, yend = Cell),size = 1) + geom_point(aes(size = cor1))+ theme_bw()+ labs(size = "Cor") p ## 添加p值 dat$pvalue2 <- cut(dat$pvalue, breaks = c(0, 0.05,1), labels = c("< 0.05","> 0.05"), right=FALSE) p1 = ggplot()+ geom_text(dat,mapping = aes(x = 0, y = Cell, color = pvalue2, label = round(pvalue,3)))+ scale_color_manual(name="", values = c("red", "black"))+ theme_void()+ guides(color=F) p1 library(patchwork) p|p1 ggsave("lollipop.pdf",width = 8,height = 5)
result
后续在AI
里调整一下位置即可~当然用基础函数或其他办法也能够直接画出来,这里我就不想了,有更好的办法的同学可以私信我。