论文
Independent phenotypic plasticity axes define distinct obesity sub-types
https://www.nature.com/articles/s42255-022-00629-2#Sec15
s42255-022-00629-2.pdf
论文中没有公开代码,但是所有作图数据都公开了,我们可以试着用论文中提供的数据模仿论文中的图
今天的推文重复一下论文中的Fig3b 差异表达火山图,之前也有推文介绍过火山图,今天的推文主要学习的一个知识点是利用latex2exp这个R包添加文本,包括
ggplot()+ geom_point(aes(x=1,y=1))+ labs(x=TeX(r"(\overset${ABCDEF}{abcde}$)"))火山图的部分示例数据
读取数据
library(readr)df<-read_tsv("data/20220921/fig3b.txt")head(df)colnames(df)添加差异表达的分组
df %>% mutate(change=case_when( log2FoldChange > 1 & pvalue < 0.05 ~ "Up", log2FoldChange < -1 & pvalue < 0.05 ~ "Down", TRUE ~ "Not Sig" )) -> new.dftable(new.df$change)new.df %>% filter(-log10(pvalue)>8) -> new.text.label这里没有找到论文中差异表达的标准,这里是我随便写的
作图代码
library(ggplot2)library(ggrepel)library(latex2exp)ggplot(data=new.df,aes(x=log2FoldChange,y=-log10(pvalue)))+ geom_point(aes(color=change))+ scale_color_manual(values = c("Down"="#3a53a4", "Not Sig"="#aaaaaa", "Up"="#7acde4"), labels=c("Down"=TeX(r"(\textit{Nnat}${^+}$${^/}$${^-}$${^p}$-\textit{Heavy} depleted)"), "Not Sig"="Not Significant", "Up" = TeX(r"(\textit{Nnat}${^+}$${^/}$${^-}$${^p}$-\textit{Heavy} enriched)")))+ theme_classic()+ theme(legend.position = c(0.2,0.9), legend.text.align = 0, legend.title = element_blank())+ geom_text_repel(data=new.text.label, aes(x=log2FoldChange,y=-log10(pvalue), label=mgi_symbol))+ labs(x=TeX(r"(\overset${\textit{Nnat}{^+}{^/}{^-}{^p}-\textit{Lean}$ versus $\textit{Nnat}{^+}{^/}{^-}{^p}-\textit{Giant}}{(log{_2}$ fold $change)}$)"), y=TeX(r"(-log${_1}{_0}$ {(}\textit{P}{ value}{)})"))
制作封面图
p1<-ggplot(data=new.df,aes(x=log2FoldChange,y=-log10(pvalue)))+ geom_point(aes(color=change))+ scale_color_manual(values = c("Down"="#3a53a4", "Not Sig"="#aaaaaa", "Up"="#7acde4"), labels=c("Down"=TeX(r"(\textit{Nnat}${^+}$${^/}$${^-}$${^p}$-\textit{Heavy} depleted)"), "Not Sig"="Not Significant", "Up" = TeX(r"(\textit{Nnat}${^+}$${^/}$${^-}$${^p}$-\textit{Heavy} enriched)")))+ theme_classic()+ theme(legend.position = c(0.2,0.9), legend.text.align = 0, legend.title = element_blank())+ geom_text_repel(data=new.text.label, aes(x=log2FoldChange,y=-log10(pvalue), label=mgi_symbol))+ labs(x=TeX(r"(\overset${\textit{Nnat}{^+}{^/}{^-}{^p}-\textit{Lean}$ versus $\textit{Nnat}{^+}{^/}{^-}{^p}-\textit{Giant}}{(log{_2}$ fold $change)}$)"), y=TeX(r"(-log${_1}{_0}$ {(}\textit{P}{ value}{)})"))p2<-ggplot(data=new.df,aes(x=log2FoldChange,y=-log10(pvalue)))+ geom_point(aes(color=change))+ scale_color_manual(values = c("Down"="red", "Not Sig"="#aaaaaa", "Up"="darkgreen"), labels=c("Down"=TeX(r"(\textit{Nnat}${^+}$${^/}$${^-}$${^p}$-\textit{Heavy} depleted)"), "Not Sig"="Not Significant", "Up" = TeX(r"(\textit{Nnat}${^+}$${^/}$${^-}$${^p}$-\textit{Heavy} enriched)")))+ theme_classic()+ theme(legend.position = c(0.2,0.9), legend.text.align = 0, legend.title = element_blank())+ geom_text_repel(data=new.text.label, aes(x=log2FoldChange,y=-log10(pvalue), label=mgi_symbol))+ labs(x=TeX(r"(\overset${\textit{Nnat}{^+}{^/}{^-}{^p}-\textit{Lean}$ versus $\textit{Nnat}{^+}{^/}{^-}{^p}-\textit{Giant}}{(log{_2}$ fold $change)}$)"), y=TeX(r"(-log${_1}{_0}$ {(}\textit{P}{ value}{)})"))library(patchwork)pdf(file = "Rplot03.pdf",width = 14.1,height = 6)p1+p2dev.off()示例数据和代码可以给推文点赞 点击在看 最后留言获取
欢迎大家关注我的公众号
小明的数据分析笔记本
小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!
|