示例图片
输入文件格式:
实现代码
library(ggplot2)
library(aplot)
library(forcats)
library(dplyr)
A= read.delim('plot.data.xls', sep = '\t', check.names = FALSE,header = 1) #读取数据
A$Description = as.factor(A$Description) #转化为因子型,固定顺序
A$Description = fct_inorder(A$Description) #Level的顺序定为表中的顺序
A$Type =as.factor(A$Type)
A$Species=as.factor(A$Species)
p1=ggplot(A, aes(Species, Description)) +
geom_point(aes(color=Pvalue, size=Fold_Enrichment))+
facet_grid(Class~Type,scales = "free",space = "free")+ #分面
theme_bw()+
theme(panel.grid = element_blank(),
axis.text.x=element_text(size = 8,angle=90,colour = "black",hjust = 1,vjust=0.5), #定义X轴字体
axis.text.y = element_text(size = 8,colour = "black",hjust = 1,vjust=0.5),
#定义Y轴字体
strip.text.x = element_text(size=8, colour = "black",face="bold"),
#定义X 分面字体
strip.text.y = element_text(size=8, colour = "black",face="bold",angle = 0),
#定义Y 分面字体
strip.background.x = element_rect(fill=c("#4DBDAB")),
#定义X 分面背景颜色
strip.background.y = element_rect(fill="#D4FF8A")
#定义 Y分泌背景颜色
)+
scale_colour_gradientn(colours = c('#DB0000','#FFAA58','#28FF43'),
limits = c(0, 0.05),
na.value = "grey")+ #设定Pvalue颜色范围,小于0.05的定义为灰色
labs(x=NULL,y=NULL)+
guides(size=guide_legend(order=1))+
scale_y_discrete(position = "left")#y轴文字放右侧
pdf("plot.pdf",height = 10,width =15)
p1
dev.off()