復(fù)現(xiàn)Cell圖表(片尾彩蛋):3D餅圖展示細(xì)胞比例

先來個(gè)簡單的,之前有小伙伴咨詢一篇Cell文章中的餅圖,展示的是celltype比例,其實(shí)之前我們寫過很多展示細(xì)胞比例的圖,這里復(fù)現(xiàn)這個(gè)3D版的正好彌補(bǔ)我們沒有介紹過3D餅圖的做法。我們這里使用的是R語言,當(dāng)然了,其他更接近的做法可以使用Matlab繪制。


(reference: Fibroblast inflammatory priming determines regenerative versus fibrotic skin repair in reindeer)

我們復(fù)現(xiàn)效果如果,要達(dá)到原文的效果,需要自行排版修改!


image.png

3D效果的實(shí)現(xiàn)采用plotrix包,首先加載數(shù)據(jù)及包:這里我們直接用的單細(xì)胞數(shù)據(jù),統(tǒng)計(jì)了兩組的各種celltype的細(xì)胞數(shù)。假設(shè)你是其他的數(shù)據(jù),整理統(tǒng)計(jì)即可。


setwd('D:\\KS項(xiàng)目\\公眾號(hào)文章\\3D餅圖展示細(xì)胞比例')

library(Seurat)
library(plotrix)#繪制3D餅圖
human_data <- readRDS("D:/KS項(xiàng)目/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

#最后增加一個(gè)參數(shù)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

如果想要各個(gè)扇形錯(cuò)位,調(diào)整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效果就可以了,還是強(qiáng)調(diào)一下,作圖只是對(duì)您文章的添彩,并不能解決本質(zhì)問題,還是需要在數(shù)據(jù)實(shí)驗(yàn)上下功夫。希望我們的分享對(duì)您有用,點(diǎn)個(gè)贊再走唄!

此外,這篇《cell》中還有一幅圖是小伙伴感興趣的,如下:


image.png

那么這個(gè)還需要復(fù)現(xiàn)嗎?如果您真的了解我們,可能2年前的帖子我們就復(fù)現(xiàn)過,另外一篇文章中的一樣的圖,請(qǐng)參考:復(fù)現(xiàn)Nature medicine圖表---堆疊柱狀圖顯示每個(gè)樣本上下調(diào)差異基因!所以說,沒事干可以多翻翻我們往期內(nèi)容,說不定就能找到你需要的東西。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容