10X空間轉(zhuǎn)錄組繪圖之細(xì)胞類型百分比餅圖和空間密度分布圖

hello,周四了,一周又即將過(guò)去,不知道大家有沒(méi)有感覺(jué)到時(shí)光飛逝,時(shí)間啊,慢些吧,給自己點(diǎn)時(shí)間可以思考。

這一篇教給大家一個(gè)簡(jiǎn)單的內(nèi)容,畫(huà)圖,一張是細(xì)胞類型占比餅圖,一張是細(xì)胞密度空間分布圖,如下圖:

圖片.png

圖片.png

我們首先來(lái)餅圖

library(Seurat)
library(ggplot2)
###讀取數(shù)據(jù),讀入自己的數(shù)據(jù)
Spatial = readRDS(Seurat_spatial_rds)
anno = read.csv(sp_sc_joint,header = T,row.names = 1,check.names = F)###單細(xì)胞空間聯(lián)合分布矩陣

coor = Spatial@images$image@coordinates[,c(5,4)]
meta = rbind(coor,anno)

head(meta)
圖片.png
colnames(meta)[1:2] = c('x','y')
st_meta$x <- (st_meta$x - min(st_meta$x))/(max(st_meta$x) - 
        min(st_meta$x))
st_meta$y <- (st_meta$y - min(st_meta$y))/(max(st_meta$y) - 
        min(st_meta$y))
cellname <- colnames(meta)[-c(1:2)]

col_manual <- ggpubr::get_palette(palette = "lancet", 
            k = length(cellname))####顏色

ggplot2::ggplot() + scatterpie::geom_scatterpie(data = st_meta, 
        ggplot2::aes(x = x, y = y), col = cellname, color = NA, 
        pie_scale = pie_scale) + ggplot2::coord_fixed(ratio = 1) + 
        ggplot2::scale_fill_manual(values = col_manual) + ggplot2::theme_bw() + 
        ggplot2::theme(panel.grid = ggplot2::element_blank()) + 
        ggplot2::labs(x = "scaled_x", y = "scaled_y")
就可以得到細(xì)胞類型分布的餅圖了
圖片.png

然后下一張圖,看某種細(xì)胞類型的空間分布

col_manual <- ggpubr::get_palette(palette = "lancet", 
            k = length(cellname))
        point_color <- col_manual[which(cellname == celltype)]

st_meta <- st_meta[st_meta$celltype == celltype, ]
p <- ggplot2::ggplot(data = st_meta, ggplot2::aes(x, y)) + 
        ggplot2::theme_bw() + ggplot2::theme(panel.grid = ggplot2::element_blank())

p <- p + ggplot2::geom_point(size = point_size, color = point_color)

p <- p + ggplot2::stat_density2d(ggplot2::aes(color = ..level..), 
            size = size)

p + scale_color_gradient(low = color_low, high = color_high)

color_midpoint <- stats::median(st_meta$gene)

p + scale_color_gradient2(low = color_low, mid = color_mid, 
                high = color_high, midpoint = color_midpoint)

print(p)
就拿到了下面的結(jié)果
圖片.png

其中剛開(kāi)始用

p <- p + ggplot2::stat_density2d(ggplot2::aes(fill = ..density..), 
            geom = "raster", contour = F)

就會(huì)得到下面的圖

圖片

你學(xué)會(huì)了么,生活很好,有你更好

最后編輯于
?著作權(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),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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