美文网首页
ktplots(三):其它个性化绘图

ktplots(三):其它个性化绘图

作者: 生信宝库 | 来源:发表于2023-07-01 21:05 被阅读0次

    前言

    鉴于ktplots系列的前两个推文:ktplots(一):绘制个性化气泡图ktplots(二):个性化绘制通路信号联系都很受欢迎,于是Immugent就马不停蹄的更新了有关ktplots包的其它绘图技巧。

    跟前两篇主要关注某一种图的展示不同,本篇推文主要是介绍ktplots包的其它零碎的绘图技巧。当然,所使用的数据也是各式各样,可能需要小伙伴自己准备相应的数据。此外,ktplots还有很多其它功能,感兴趣的小伙伴可以去其github上学习研究。


    代码流程

    data(kidneyimmune)
    plot_cpdb_heatmap(kidneyimmune, 'celltype', pvals2, cellheight = 10, cellwidth = 10)
    
    image.png
    plot_cpdb_heatmap(kidneyimmune, 'celltype', pvals2, cellheight = 10, cellwidth = 10, symmetrical = FALSE)
    
    image.png

    Plotting gene expression dot plots heatmaps.

    # Note, this conflicts with tidyr devel version
    geneDotPlot(scdata = kidneyimmune, # object
        genes = c("CD68", "CD80", "CD86", "CD74", "CD2", "CD5"), # genes to plot
        idents = "celltype", # column name in meta data that holds the cell-cluster ID/assignment
        split.by = 'Project', # column name in the meta data that you want to split the plotting by. If not provided, it will just plot according to idents
        standard_scale = TRUE) + # whether to scale expression values from 0 to 1. See ?geneDotPlot for other options
    theme(strip.text.x = element_text(angle=0, hjust = 0, size =7)) + small_guide() + small_legend()
    
    image.png
    library(ggplot2)
    scRNAseq <- Seurat::SCTransform(scRNAseq, verbose = FALSE) %>% Seurat::RunPCA(., verbose = FALSE) %>% Seurat::RunUMAP(., dims = 1:30, verbose = FALSE)
    anchors <- Seurat::FindTransferAnchors(reference = scRNAseq, query = spatial, normalization.method = "SCT")
    predictions.assay <- Seurat::TransferData(anchorset = anchors, refdata = scRNAseq$label, dims = 1:30, prediction.assay = TRUE, weight.reduction = spatial[["pca"]])
    spatial[["predictions"]] <- predictions.assay
    Seurat::DefaultAssay(spatial) <- "predictions"
    Seurat::DefaultAssay(spatial) <- 'SCT'
    pa <- Seurat::SpatialFeaturePlot(spatial, features = c('Tnfsf13b', 'Cd79a'), pt.size.factor = 1.6, ncol = 2, crop = TRUE) + viridis::scale_fill_viridis()
    Seurat::DefaultAssay(spatial) <- 'predictions'
    pb <- Seurat::SpatialFeaturePlot(spatial, features = 'Group1-3', pt.size.factor = 1.6, ncol = 2, crop = TRUE) + viridis::scale_fill_viridis()
    
    p1 <- correlationSpot(spatial, genes = c('Tnfsf13b', 'Cd79a'), celltypes = 'Group1-3', pt.size.factor = 1.6, ncol = 2, crop = TRUE) + scale_fill_gradientn( colors = rev(RColorBrewer::brewer.pal(12, 'Spectral')),limits = c(-1, 1))
    p2 <- correlationSpot(spatial, genes = c('Tnfsf13b', 'Cd79a'), celltypes = 'Group1-3', pt.size.factor = 1.6, ncol = 2, crop = TRUE, average_by_cluster = TRUE) + scale_fill_gradientn(colors = rev(RColorBrewer::brewer.pal(12, 'Spectral')),limits = c(-1, 1)) + ggtitle('correlation averaged across clusters')
    
    cowplot::plot_grid(pa, pb, p1, p2, ncol = 2)
    
    image.png

    As shown in the examples above, these are some functions to quickly adjust the size and position of ggplots.

    # for example
    g <- Seurat::DimPlot(kidneyimmune, group.by = "celltype")
    g1 <- g + small_legend() + small_guide() + small_axis() + bottomleft_legend()
    library(patchwork)
    g + g1
    
    image.png

    说在最后

    今天的推文介绍了很多种不同的绘图方式,其中Immugent最喜欢利用空间转录组数据进行信号共定位的展示方式。因为小编自己最近也在分析空转数据,迫切也需要这种将共定位信号进行展示的绘图手段。截止到目前,有关ktplots包的所有绘图技巧都已经更新完毕。如果有小伙伴知道其它较为优质的绘图包,可以通过后台联系我们,我们也会更新相应的教程。

    好啦,本期分享到这里就结束了,我们下期再会~~

    相关文章

      网友评论

          本文标题:ktplots(三):其它个性化绘图

          本文链接:https://www.haomeiwen.com/subject/mppxudtx.html