发布日期:2023-09-13 22:11 点击次数:117
详情请联系作者:
❞玩转单细胞往期精彩系列:玩转单细胞(2):Seurat批量做图修饰玩转单细胞(3):堆叠柱状图添加比例玩转单细胞(4):单细胞相关性玩转单细胞(5):单细胞UMAP图只标记特定细胞群、圈定细胞群及坐标轴修改玩转单细胞(6):单细胞差异基因展示之对角散点图玩转单细胞(7):修改Seurat对象基因名称玩转单细胞(8): 单细胞3维聚类图展示玩转单细胞(9):单细胞Seurat对象数据操作玩转单细胞(10):替换单细胞Seurat对象UMAP坐标事情是这样的,我们在寻找合适的免疫组库数据的时候看到一篇nature communication的文章,里面有个图挺好的。进一步看到,这篇文章作者提供了所有图片的代码,链接:https://doi.org/10.5281/ zenodo.7806635,原文Code availability部分。其实这篇文章的其他图和代码很普通,就是常规的一些操作,对于初学者可能比较友好,可以自己尝试学一学。之所以要说这个,是因为其中有两个地方比较有意思,细节的问题,我们之前的代码没有提到过所以这里写一下!本文详细注释代码已上传群文件,可自行下载!
图片
(reference:Age-associated B cells predict impaired humoral immunity after COVID-19 vaccination in patients receiving immune checkpoint blockade)
首先是第一个问题:我们在使用Seurat包的DimPlot函数做降维聚类图的时候,legend的顺序有时候想调整(或者clusters用数字的时候,排列并不是从小到大排列),或者VlnPlot和DotPlot函数作图的时候,想调整cell type顺序。我们知道在ggplot作图的时候我们可以使用factor或者forcats包固定顺序,那么在Seurat下怎么调整?其实只需要levels函数设置seurat对象active idents顺序即可。library(Seurat)library(ggplot2)Idents(uterus) <- "celltype"levels(uterus)DimPlot(uterus)levels(uterus) <- c("Lymphocytes","Unciliated epithelial cells","Ciliated epithelial cells", "Smooth muscle cells", "Stromal fibroblasts", "Endothelial cells","Macrophages")DimPlot(uterus)
图片
第二个问题就是开头提到的那个分面图。一般正常使用DotPlot的时候,feature是向量,是不会有分面效果的。当把feature(每个分组type的基因)传入为list的时候,seurat的DotPlot就可以有分面效果了。DefaultAssay(uterus) <- "RNA"SMC_genes <- c("ACTA2", "RGS5")MAC_genes <- c("MS4A6A", "CD68","LYZ")LY_genes <- c("CCL5", "STK17B","PTPRC")SF_genes <- c("DCN", "COL6A3", "LUM")EC_genes <- c("PECAM1","PCDH17", "VWF")UEP_genes <- c("EPCAM", "CDH1")EP_genes <- c("FOXJ1","CDHR3","DYDC2")levels(uterus) <- c("Lymphocytes","Unciliated epithelial cells","Ciliated epithelial cells",竞技宝电竞 "Smooth muscle cells", "Stromal fibroblasts", "Endothelial cells","Macrophages")features <- list("LY" = LY_genes, "UEP" = UEP_genes, "EP" = EP_genes, "SMC" = SMC_genes, "SF" = SF_genes, "EC" = EC_genes, "MAC" = MAC_genes)p <- DotPlot(object = uterus, features=features)
图片
其实,按照ggplot的方式在这个图上继续修饰就可以得到完美的图了,参考:NCS质感图表:Seurat单细胞DotPlot函数基因表达气泡图修饰。这里我们提取数据用ggplot2完成。p1 <- ggplot(p$data, aes(x = features.plot, y = id)) + geom_point(aes(size = pct.exp, color = avg.exp.scaled)) + facet_grid(facets = ~feature.groups, switch = "x", scales = "free_x", space = "free_x") + scale_radius(breaks = c(25, 50, 75, 100), range = c(0,6)) + theme_classic() + scale_color_gradient2(low = "blue", mid = "white", high = "red")+ theme(axis.text.x = element_text(angle = 90, face = 1, size = 12, family = "Arial Narrow", hjust = 1, vjust = 0.5, color = "black"), axis.text.y = element_text(size = 12, face = 1, family = "Arial Narrow", color = "black"), legend.text = element_text(size = 8, face = 1, family = "Arial Narrow"), legend.title = element_text(size = 10, face = 1, family = "Arial Narrow"), legend.position = 'top' , strip.placement = "outside", strip.text.x = element_text(size = 12, family = "Arial Narrow Bold"), axis.title = element_blank())+ guides(colour = guide_colourbar(title.vjust = 0.9, title.hjust = 0))+ labs(size = "Percent Expressed", color = "Average Expression")
图片
这里有一个点我们之前从未提过,就是在ggplot2画板任意位置添加文字。这篇文章的代码里有一个简单的方法,就是labs函数,theme主题里面调整位置即可。
p1+ labs(tag = "Defining \ngenes of:")+ theme(plot.tag.position = c(0.14, 0.05), plot.tag = element_text(size = 12,family = "Arial Narrow Bold"))
图片
这就是我们要分享的所有内容了,虽然很简单竞技宝电竞,但是确很细节,希望对你的学习有所启发和帮助。觉得分享有用的点个赞再走呗!
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报。