Fig1-a 作出散点图并显示拟合曲线和公式,添加标注文字 20

2022-04-14  本文已影响0人  RashidinAbdu
image.png

文献名称: Blood metabolome predicts gut microbiome α-diversity in humans

Nature Biotechnology: volume 37, pages1217–1228(2019)
image.png

1.数据准备与读取:

image.png
library(readxl)
DF<-as.data.frame(read_xlsx(file.choose()))
head(DF)
image.png

2.作图与修饰:

library(ggplot2)
p1 <- ggplot(data = DF, aes(x = DF$`mShannon diversity`, y = DF$`Observed Shannon diversity`)) + geom_point() 
p1
image.png
p3<-p1+geom_smooth(method = "lm", se=FALSE, color="red", formula = y ~ x) 
p3
image.png
p4<-p3+  theme_bw()
p4
image.png
p5<-p4+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),panel.background = element_blank(), axis.line = element_line(colour = "black"))
p5
image.png
p6<-p5+ theme(panel.border = element_blank())
p6
image.png
p7<-p6+ggtitle("a") + xlab("mShannon diversity") + ylab("Observed Shannon diversity")
p7
image.png
p8<-p7+annotate(geom="text", x=2.361, y=5.4, label= "Out-of-sample ")+annotate(geom="text", x=2.734, y=5.4, label=expression(R^{2}))+annotate(geom="text", x=2.93, y=5.4, label= "= 0.45") +annotate(geom="text", x=2.5,y=5.1, label= " Pearson’s  r = 0.68")+annotate(geom="text", x=2.461, y=4.7, label= "P = 3.21 × ")+annotate(geom="text", x=2.74, y=4.754, label=expression(10^{-56})) 
p8
image.png
p9<-p8+scale_x_continuous( breaks = seq(2,5.5,by=0.5))+scale_y_continuous( breaks = seq(2,5.5,by=0.5) )
p9
image.png

3. 保存与输出:

ggsave(plot = p9, width =8, height = 6, dpi = 300, filename = "C:/Users/Mr.R/Desktop/Fig1_a.jpg")

4. 完整的代码为:

library(ggplot2)
p1 <- ggplot(data = DF, aes(x = DF$`mShannon diversity`, y = DF$`Observed Shannon diversity`)) + geom_point() 
p1

p3<-p1+geom_smooth(method = "lm", se=FALSE, color="red", formula = y ~ x) 
p3

p4<-p3+  theme_bw()
p4
p5<-p4+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),panel.background = element_blank(), axis.line = element_line(colour = "black"))
p5
p6<-p5+ theme(panel.border = element_blank())
p6
p7<-p6+ggtitle("a") + xlab("mShannon diversity") + ylab("Observed Shannon diversity")
p7

p8<-p7+annotate(geom="text", x=2.361, y=5.4, label= "Out-of-sample ")+annotate(geom="text", x=2.734, y=5.4, label=expression(R^{2}))+annotate(geom="text", x=2.93, y=5.4, label= "= 0.45") +annotate(geom="text", x=2.5,y=5.1, label= " Pearson’s  r = 0.68")+annotate(geom="text", x=2.461, y=4.7, label= "P = 3.21 × ")+annotate(geom="text", x=2.74, y=4.754, label=expression(10^{-56})) 
p8

p9<-p8+scale_x_continuous( breaks = seq(2,5.5,by=0.5))+scale_y_continuous( breaks = seq(2,5.5,by=0.5) )
image.png
上一篇 下一篇

猜你喜欢

热点阅读