❝详情请联系作者:
❞
事情是这样的,我们在寻找合适的免疫组库数据的时候看到一篇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)
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)
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)
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"))
这就是我们要分享的所有内容了,虽然很简单,但是确很细节,希望对你的学习有所启发和帮助。觉得分享有用的点个赞再走呗!
联系客服