700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 跟着Nature Microbiology学作图:R语言ggplot2做散点图添加拟合曲线和p值

跟着Nature Microbiology学作图:R语言ggplot2做散点图添加拟合曲线和p值

时间:2023-08-08 10:34:08

相关推荐

跟着Nature Microbiology学作图:R语言ggplot2做散点图添加拟合曲线和p值

本地文件s41564-021-00997-7.pdf

论文

Protective role of the Arabidopsis leaf microbiota against a bacterial pathogen

image.png

今天的推文来重复一下论文中的figure3c 散点图添加拟合曲线

image.png

读取数据集

library(readxl)df<-read_excel("41564__997_MOESM10_ESM.xlsx")head(df)colnames(df)

最基本的散点图

library(ggplot2)ggplot(data=df,aes(x=`meanProtectionScore[a.u.]`,y=`meanColonization[log10(CFU/mg)]`))+geom_point(aes(color=Phylum))+ggsave(filename="fig3c.pdf",width=6,height=4,family="serif")

添加拟合曲线

ggplot(data=df,aes(x=`meanProtectionScore[a.u.]`,y=`meanColonization[log10(CFU/mg)]`))+geom_point(aes(color=Phylum))+geom_smooth(method="lm",formula="y~x",se=F,color="grey")+ggsave(filename="fig3c.pdf",width=6,height=4,family="serif")

计算拟合方程的R和P值

df.lm<-lm(`meanColonization[log10(CFU/mg)]`~`meanProtectionScore[a.u.]`,data=df)summary(df.lm)sqrt(0.242)ggplot(data=df,aes(x=`meanProtectionScore[a.u.]`,y=`meanColonization[log10(CFU/mg)]`))+geom_point(aes(color=Phylum))+geom_smooth(method="lm",formula="y~x",se=F,color="grey")+annotate(geom="text",x=60,y=1.2,label=expression(italic(R)~"="~0.49~","~italic(P)~"="~5.4%*%10^-15),parse=T)+ggsave(filename="fig3c.pdf",width=6,height=4,family="serif")

image.png

添加虚线注释框

ggplot(data=df,aes(x=`meanProtectionScore[a.u.]`,y=`meanColonization[log10(CFU/mg)]`))+geom_point(aes(color=Phylum))+geom_smooth(method="lm",formula="y~x",se=F,color="grey")+annotate(geom="text",x=60,y=1.2,label=expression(italic(R)~"="~0.49~","~italic(P)~"="~5.4%*%10^-15),parse=T)+annotate(geom="rect",xmin=75,xmax=100,ymin=4.5,ymax=7,alpha=0,color="black",lty="dashed")+ggsave(filename="fig3c.pdf",width=6,height=4,family="serif")

image.png

最后是调节主题美化

colors<-c("#96d796","#aed75b","#599943","#499ef1","#f18282","#ffdf33")ggplot(data=df,aes(x=`meanProtectionScore[a.u.]`,y=`meanColonization[log10(CFU/mg)]`))+geom_point(aes(fill=Phylum,color=Phylum),shape=21,key_glyph="rect")+geom_smooth(method="lm",formula="y~x",se=F,color="grey")+annotate(geom="text",x=60,y=1.2,label=expression(italic(R)~"="~0.49~","~italic(P)~"="~5.4%*%10^-15),parse=T)+annotate(geom="rect",xmin=75,xmax=100,ymin=4.5,ymax=7,alpha=0,color="black",lty="dashed")+theme_bw()+theme(panel.grid=element_blank(),legend.title=element_blank())+scale_fill_manual(values=colors)+scale_color_manual(values=colors)+ggsave(filename="fig3c.pdf",width=9.4,height=4,family="serif")

image.png

小明的数据分析笔记本

小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。