先来个简单的,之前有小伙伴咨询一篇Cell文章中的饼图,展示的是celltype比例,其实之前我们写过很多展示细胞比例的图,这里复现这个3D版的正好弥补我们没有介绍过3D饼图的做法。我们这里使用的是R语言,当然了,其他更接近的做法可以使用Matlab绘制。
(reference: Fibroblast inflammatory priming determines regenerative versus fibrotic skin repair in reindeer)
我们复现效果如果,要达到原文的效果,需要自行排版修改!
image.png
3D效果的实现采用plotrix包,首先加载数据及包:这里我们直接用的单细胞数据,统计了两组的各种celltype的细胞数。假设你是其他的数据,整理统计即可。
setwd('D:\\KS项目\\公众号文章\\3D饼图展示细胞比例')
library(Seurat)
library(plotrix)#绘制3D饼图
human_data <- readRDS("D:/KS项目/human_data.rds")
cellratio <- as.data.frame(table(human_data$group, human_data$celltype))
BM <- subset(cellratio, Var1=='BM')
GM <- subset(cellratio, Var1=='GM')
# write.csv(BM, file = "BM.csv")
# write.csv(GM, file = "GM.csv")
作图:
#plot
par(mfrow = c(1,2), xpd=TRUE)
pie3D(x=BM$Freq,
radius=1,
height=0.1,
theta=pi/6,
explode=0,
main="Celltype fraction of BM",
col=c("#d2981a", "#a53e1f", "#457277", "#8f657d", "#8dcee2"),
border = "black",
shade = 0.5,
labels=paste0(c(BM$Var2),
"\n",
round(BM$Freq/sum(BM$Freq) * 100,2), "%"),
mar=c(2,2,2,3),
labelcol = "black",
labelcex = 0.8
)
pie3D(x=GM$Freq,
radius=1,
height=0.1,
theta=pi/6,
explode=0,
main="Celltype fraction of GM",
col=c("#d2981a", "#a53e1f", "#457277", "#8f657d", "#8dcee2"),
border = "black",
shade = 0.5,
labels=paste0(c(GM$Var2),
"\n",
round(GM$Freq/sum(BM$Freq) * 100,2), "%"),
mar=c(2,2,2,3),
labelcol = "black",
labelcex = 0.8
)
image.png
A = pie3D(x=BM$Freq,
radius=1,
height=0.1,
theta=pi/6,
explode=0,
main="BM",
col=c("#d2981a", "#a53e1f", "#457277", "#8f657d", "#8dcee2"),
border = "black",
shade = 0.5,
labels=paste0(c(BM$Var2),
"\n",
round(BM$Freq/sum(BM$Freq) * 100,2), "%"),
mar=c(2,2,2,3),
labelcol = "black",
labelcex = 0.8
)
A
# [1] 1.961312 4.319378 5.117877 5.776638 6.158420
A[5] <- 6.5
#最后增加一个参数labelpos
pie3D(x=BM$Freq,
labelpos=A,
radius=1,
height=0.1,
theta=pi/6,
explode=0,
main="BM",
col=c("#d2981a", "#a53e1f", "#457277", "#8f657d", "#8dcee2"),
border = "black",
shade = 0.5,
labels=paste0(c(BM$Var2),
"\n",
round(BM$Freq/sum(BM$Freq) * 100,2), "%"),
mar=c(2,2,2,3),
labelcol = "black",
labelcex = 0.8
)
image.png
如果想要各个扇形错位,调整explode即可
pie3D(x=BM$Freq,
labelpos=A,
radius=1,
height=0.1,
theta=pi/6,
explode=0.1,
main="BM",
col=c("#d2981a", "#a53e1f", "#457277", "#8f657d", "#8dcee2"),
border = "black",
shade = 0.5,
labels=paste0(c(BM$Var2),
"\n",
round(BM$Freq/sum(BM$Freq) * 100,2), "%"),
mar=c(2,2,2,3),
labelcol = "black",
labelcex = 0.8
)
image.png
这样3D效果就可以了,还是强调一下,作图只是对您文章的添彩,并不能解决本质问题,还是需要在数据实验上下功夫。希望我们的分享对您有用,点个赞再走呗!
此外,这篇《cell》中还有一幅图是小伙伴感兴趣的,如下:
image.png
那么这个还需要复现吗?如果您真的了解我们,可能2年前的帖子我们就复现过,另外一篇文章中的一样的图,请参考:复现Nature medicine图表---堆叠柱状图显示每个样本上下调差异基因!所以说,没事干可以多翻翻我们往期内容,说不定就能找到你需要的东西。