美文网首页RNA-seqR语言
奇葩颜色搭配影响图例

奇葩颜色搭配影响图例

作者: 一路向前_莫问前程_前程似锦 | 来源:发表于2018-09-13 17:35 被阅读21次
image.png
options(stringsAsFactors = F)

easydf<-read.table("GO.csv",sep = ",",header = T)
library(stringr)
head(easydf$GeneRatio)
str(easydf$GeneRatio)
easydf$GeneRatio=as.numeric(easydf$GeneRatio)

sortdf<-easydf[order(as.numeric(easydf$GeneRatio)) ,]

sortdf$GO.Term=str_c(sortdf$Description,sortdf$ID,sep = " ")

sortdf$GO.Term<-factor(sortdf$GO.Term,levels = sortdf$GO.Term)

sortdf$P=-log10(sortdf$pvalue)

library(ggplot2)
pr<-ggplot(sortdf,aes(GeneRatio,GO.Term,size=Count,
                      colour=pvalue))+#横坐标、纵坐标、颜色代表p-value
  geom_point()+#圆点的大小代表组内基因数
  scale_color_gradientn(colours=c("red","blue"))+#可以自己改颜色
  #圆点的大小代表Number of significant genes
  scale_size_continuous(range = c(2,10))+#圆点的大小范围
  scale_x_continuous(limits = c(0.01,0.1))+#设置x轴范围
  theme_bw(15)+#背景变成白色
  ylab("")+
  scale_y_discrete(position = "right")+#把term放到右侧
  theme(legend.position=c(0,0),legend.justification = c(0,0))+#legend画在左下角
  #下面两行让legend融入图
  theme(legend.background = element_blank())+#移除legend整体的边框
  theme(legend.key = element_blank())#移除legend每个项目周围的边框
pr


easydf<-read.table("kegg.csv",header = T,sep = ",",as.is = T)

sortdf<-easydf[order(easydf$GeneRatio),]

sortdf$GO.Term=str_c(sortdf$Description,sortdf$ID,sep = " ")


sortdf$GO.Term<-factor(sortdf$GO.Term,levels = sortdf$GO.Term)

library(ggplot2)
pl<-ggplot(sortdf,aes(GeneRatio,GO.Term,size=Count,
                      colour=pvalue))+
  geom_point()+
  scale_color_gradientn(colours=c("red","blue"))+
  scale_size_continuous(range = c(2,10))+
  scale_x_continuous(limits = c(0.01,0.1))+
  theme_bw(15)+
  ylab("")+
  theme(legend.position=c(1,0),legend.justification = c(1,0))+#legend画在右下角
  #下面两行让legend融入图
  theme(legend.background = element_blank())+#移除legend整体的边框
  theme(legend.key = element_blank())#移除legend每个项目周围的边框

pl



library(cowplot)


plot_grid(pl, pr, labels = "")

如果是red + yellow就出现下面的bug,究竟为什么?表示不知道

image.png

kegg csv


image.png

gocsv
小数


image.png

相关文章

网友评论

    本文标题:奇葩颜色搭配影响图例

    本文链接:https://www.haomeiwen.com/subject/fmcggftx.html