跟着Nature Microbiology学作图:R语言ggplot2做散点图添加拟合曲线和p值
2023-03-20 15:38:23 时间
本地文件 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_2021_997_MOESM10_ESM.xlsx")
head(df)
colnames(df)
最基本的散点图
library(ggplot2)
ggplot(data=df,aes(x=`mean Protection Score [a.u.]`,
y=`mean Colonization [log10(CFU/mg)]`))+
geom_point(aes(color=Phylum))+
ggsave(filename = "fig3c.pdf",
width = 6,
height = 4,
family="serif")
添加拟合曲线
ggplot(data=df,aes(x=`mean Protection Score [a.u.]`,
y=`mean Colonization [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(`mean Colonization [log10(CFU/mg)]`~
`mean Protection Score [a.u.]`,
data=df)
summary(df.lm)
sqrt(0.242)
ggplot(data=df,aes(x=`mean Protection Score [a.u.]`,
y=`mean Colonization [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=`mean Protection Score [a.u.]`,
y=`mean Colonization [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=`mean Protection Score [a.u.]`,
y=`mean Colonization [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
相关文章
- 金融服务领域的大数据:即时分析
- 影响大数据、机器学习和人工智能未来发展的8个因素
- 从0开始构建一个属于你自己的PHP框架
- 如何将Hadoop集成到工作流程中?这6个优秀实践必看
- SEO公司使用大数据优化其模型的5种方法
- 关于Web Workers你需要了解的七件事
- 深入理解HTTPS原理、过程与实践
- 增强分析:数据和分析的未来
- PHP协程实现过程详解
- AI专家:大数据知识图谱——实战经验总结
- 关于PHP的错误机制总结
- 利用数据分析量化协同过滤算法的两大常见难题
- 怎么做大数据工作流调度系统?大厂架构师一语点破!
- 2019大数据处理必备的十大工具,从Linux到架构师必修
- OpenCV中的KMeans算法介绍与应用
- 教大家如果搭建一套phpstorm+wamp+xdebug调试PHP的环境
- CentOS下三种PHP拓展安装方法
- Go语言HTTP Server源码分析
- Go语言HTTP Server源码分析
- 2017年4月编程语言排行榜:Hack首次进入前五十