zl程序教程

您现在的位置是:首页 >  其他

当前栏目

跟着Nature Communication学作图:R语言ggplot2话点线图展示基因表达量的范围

2023-02-19 12:27:39 时间

论文

Microbiomes in the Challenger Deep slope and bottom-axis sediments

https://www.nature.com/articles/s41467-022-29144-4#code-availability

对应代码链接

https://github.com/ucassee/Challenger-Deep-Microbes

论文里提供了大部分图的数据和代码,很好的学习材料,感兴趣的同学可以找来参考,今天的推文重复一下论文中的Figure3b

示例数据集部分截图

image.png

读取数据

dat01<-read.delim("data/20220602/NC_Figure3b.txt",
                  header=TRUE,
                  check.names = FALSE,
                  sep="\t",
                  stringsAsFactors = TRUE)
head(dat01)
table(dat01$Group)
dat01$gene<-factor(dat01$gene,
                   levels = dat01$gene)

作图代码

library(ggplot2)
library(scales)

ggplot(data=dat01,aes(x=gene,y=mean_value,color=Group))+
  geom_pointrange(aes(ymin=min_value,ymax=max_value),
                  show.legend = FALSE)+
  scale_y_continuous(trans = log10_trans()
                     ,breaks = trans_breaks("log10", function(x) 10^x),
                     labels = trans_format("log10", math_format(10^.x)))+
  scale_color_manual(values=c("#BB3D00","#6F00D2","#D9006C",
                              "#005AB5","#00DB00","#3D7878","#D9B300"))+
  theme_bw() +
  theme(panel.background=element_rect(fill="white",colour="black",size=0.25),
        axis.line=element_line(colour="black",size=0.25),
        axis.title=element_text(size=13,face="plain",color="black"),
        axis.text = element_text(size=10,face="plain",color="black"),
        axis.text.x = element_text(angle = 60, hjust = 1, vjust =1),
        #legend.position="none"
  )+
  labs(x=NULL,y="TMP of genes")