单细胞-图片美化

786 阅读1分钟

1. Umap图

原图

plot3 <- DimPlot(jushi_1, label = T, pt.size = 1)+#这后面可以不写
 NoLegend()+labs(x = "UMAP1", y = "UMAP2",title = "Celltype") +
 theme(panel.border = element_rect(fill=NA,color="black", linewidth=1, linetype="solid"),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank())

image.png

美化后

library(ggsci)
library(ggplot2)
#nature版本# 这个更好看一点,用这个!
plot4 = plot3 + scale_color_npg()
#science版本
plot5 = plot3 +scale_color_aaas()
plot_grid(plot4,plot5)

image.png

2.热图

原图

DoHeatmap(scRNA_0.1,features = top10$gene)+NoLegend()

美化后

DoHeatmap(markerdata,
          features = as.character(unique(markers$markers)),
          group.by = "celltype",
          assay = 'RNA',
          group.colors = c("#00BFC4","#AB82FF","#00CD00","#C77CFF"))+
  scale_fill_gradientn(colors = c("white","grey","firebrick3"))

image.png 自定义cluster的顺序

DoHeatmap(markerdata,
          features = as.character(unique(markers$markers)),
          group.by = "celltype",
          assay = 'RNA',
          group.colors = c("#00BFC4","#AB82FF","#00CD00","#C77CFF"))+
  scale_fill_gradientn(colors = c("white","grey","firebrick3"))

image.png

3. 小提琴图

install.packages("remotes")
remotes::install_github("lyc-1995/MySeuratWrappers")#通过链接安装library(MySeuratWrappers)
markers <- c(''CD3D''''S100A8''''S100A9''''CD79A''''CCL5''''NKG7''''GZMA''''IL32''''CD4''''CD8A''''LTB''''FCN1''''MS4A1''''SPON2'',''FCER1A'',''SERPINF1''''TMEM40''''CD3E'') 
my36colors <c(''#E5D2DD''''#53A85F''''#F1BB72''''#F3B1A0''''#D6E7A3''''#57C3F3''''#476D87''''#E95C59''''#E59CC4''''#AB3282''''#23452F''''#BD956A''''#8C549C''''#585658''''#9FA3A8''''#E0D4CA''''#5F3D69''''#C5DEBA''''#58A4C3''''#E4C755''''#F7F398''''#AA9A59''''#E63863''''#E39A35''''#C1E6F3''''#6778AE''''#91D0BE''''#B53E2B''''#712820''''#DCC1DD''''#CCE0F5'',  ''#CCC9E6''''#625D9E''''#68A180''''#3A6963''''#968175'')
VlnPlot(PBMC, features = markers,
stacked=T,
pt.size=0,
cols = my36colors,#颜色 
direction = "horizontal", #水平作图
x.lab = '''', y.lab = '''')#横纵轴不标记任何东西  
+theme(axis.text.x = element_blank(), 
axis.ticks.x = element_blank())#不显示坐标刻度

4. Dotplot图

DotPlot(PBMC, features = markers)+coord_flip()+theme_bw()+#去除背景,旋转图片
theme(panel.grid = element_blank(),
axis.text.x=element_text(angle=90,hjust = 1,vjust=0.5))+#文字90度呈现
scale_color_gradientn(values = seq(0,1,0.2),ccolours = c(''#330066'',''#336699'',''#66CC66'',''#FFCC33''))#颜色渐变设置
+labs(x=NULL,y=NULL)+guides(size=guide_legend(order=3)) 

5. Featureplot图

color <- c('lightgrey', 'blue','seagreen2')#设置颜色  
plot8 <- FeaturePlot(scedata, features = 'ACKR1',cols = color, pt.size = 1)+  
  theme(panel.border = element_rect(fill=NA,color="black", size=1, linetype="solid"))#加边框 

cols = c("gray", "coral2")#这个更好看一些,这个也可以参照顶刊用图,改颜色
plot9 <- FeaturePlot(scedata, features = 'ACKR1',cols = cols, pt.size = 1)+  
  theme(panel.border = element_rect(fill=NA,color="black", size=1, linetype="solid"))#加边框 
plot_grid(plot8,plot9)

image.png

6. 堆积图

table(macro$orig.ident)#查看各组细胞数
prop.table(table(Idents(macro)))
table(Idents(macro), macro$orig.ident)#各组不同细胞群细胞数
Cellratio <- prop.table(table(macro$celltype, macro$orig.ident), margin = 2)#计算各组样本不同细胞群比例
Cellratio
Cellratio <- as.data.frame(Cellratio)
colourCount = length(unique(Cellratio$Var1))
library(ggplot2)
plot1 <- ggplot(Cellratio) + 
geom_bar(aes(x =Var2, y= Freq, fill = Var1),stat = "identity",width = 0.7,size = 0.5,colour = '#123455')+ 
theme_classic() +
labs(x='Sample',y = 'Ratio')+
coord_flip()+
scale_fill_manual(values = c("#E64B35FF","4DBBD55FF",'#00A087FF','#3C5488FF','#F39B7FFF'))#nature配图
plot1

获取顶刊配色--**pal **

pal_npg(palette = c("nrc"), alpha = 1)(8)
[1] "#E64B35FF" "#4DBBD5FF" "#00A087FF" "#3C5488FF" "#F39B7FFF" "#8491B4FF" "#91D1C2FF" "#DC0000FF"
#其他期刊获取同理
pal_aaas()
pal_jama()(7)
pal_nejm()
pal_lancet()
...

使用 scales 包可视化颜色

install.packages("scales")
devtools::install_github("r-lib/scales")

这个包里面有个函数:show_col()

show_col(pal_npg(palette = c("nrc"), alpha = 1)(8))

这样就可以知道每个颜色是什么样的

image.png