论文
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.df
table(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}{)})"))
制作封面图文章来源:https://www.toymoban.com/news/detail-720739.html
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+p2
dev.off()
示例数据和代码可以给推文点赞 点击在看 最后留言获取文章来源地址https://www.toymoban.com/news/detail-720739.html
到了这里,关于跟着NatureMetabolism学作图:R语言ggplot2转录组差异表达火山图的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!