这种图怎么画?今天就分享一下这种图的代码:
示例数据如下:
1.png
library(ggplot2)
library(ggnewscale)
library(reshape2)
library(dplyr)
a=read.csv('gene_dotplot_3li.csv',header=T,check.names=F) #读取数据
b=melt(a,id.vars = c("Cluster")) #数据融合
M1 <- c("PDGFA","COL1A1","TIMP3","CD163","CSF1R","MS4A7","CD3G","CD3E","CD3D","CD79A","MZB1") #marker list 1
M2 <- c("RASIP1","CDH5","CD1C","FCER1A","XCL1","KLRC1","MKI67","BIRC5","CLEC4C","LILRA4","MYH11","NOTCH3") #marker list 2
M <- c("PDGFA","COL1A1","TIMP3","CD163","CSF1R","MS4A7","CD3G","CD3E","CD3D","CD79A","MZB1","RASIP1","CDH5","CD1C","FCER1A","XCL1","KLRC1","MKI67","BIRC5","CLEC4C","LILRA4","MYH11","NOTCH3") #marker list
ggplot()+geom_point(data=subset(b,b$variable %in% M1),aes(variable,as.factor(Cluster),size=value,color=value))+
scale_color_gradient(low='white',high='blue')+ #左半张图
+new_scale('color')+geom_point(data=subset(b,b$variable %in% M2),aes(variable,as.factor(Cluster),size=value,color=value))+
scale_color_gradient(low='white',high='red')+scale_x_discrete(limits=M)+theme_classic()+theme(axis.text.x=element_text(angle=45,vjust=0.6,color=c('red','blue')))+ylab('Cluster') + ###右半张图和排序
theme(axis.title.x=element_text(color='blue')) + #x轴title的颜色
theme(legend.box='horizontal') #图例一行显示
搬砖就到这里,下面大家可以自主练习
网友评论