- 跟着Nature Communications 学画图~ggpl
- 跟着Nature Communications 学画图~ggpl
- 跟着Nature Communications学画图~Figur
- 跟着Nature Communications 学画图~ggpl
- 跟着Nature Genetics学画图:R语言ggplot2画
- 跟着Nature Genetics学画图:R语言ggplot2画
- 跟着Nature Genetics学画图:R语言ggplot2画
- 跟着Nature Genetics 学画图:R语言ggplot2
- 跟着Nature Genetics 学画图:R语言ggplot2
- 跟着Nature Genetics 学画图:R语言ggplot2
折线图添加误差线是非常常用的一种可视化方法,今天的推文介绍一下使用R语言的ggplot2作图的代码。模仿的是论文 Phased diploid genome assemblies and pan-genomes provide insights into the genetic history of apple domestication 中的Figure3中的d图

第一步是准备数据

数据保存为csv格式
df<-read.table("clipboard",header=T)
df
基本的折线图
library(ggplot2)
head(df)
ggplot(df,aes(x=time_point,y=value))+
geom_line()+
geom_point()+
ylim(0,40)

添加误差线
ggplot(df,aes(x=time_point,y=value))+
geom_line()+
geom_point()+
ylim(0,40)+
geom_errorbar(aes(ymin=value-sd,
ymax=value+sd),
width=0.2)

这样基本就做好了,接下来就是美化
- 去掉灰色背景
- 添加坐标轴线
- 更改坐标轴的刻度和标签
ggplot(df,aes(x=time_point,y=value))+
geom_line()+
geom_point()+
ylim(0,40)+
geom_errorbar(aes(ymin=value-sd,
ymax=value+sd),
width=0.2)+
theme(panel.background = element_blank(),
axis.line.x = element_line(),
axis.line.y = element_line())+
scale_x_continuous(breaks = 1:13,
labels = df$label)+
labs(x=NULL,y=NULL,title = "AAA")

接下来是拼图
p1<-ggplot(df,aes(x=time_point,y=value))+
geom_line()+
geom_point()+
ylim(0,40)+
geom_errorbar(aes(ymin=value-sd,
ymax=value+sd),
width=0.2)+
theme(panel.background = element_blank(),
axis.line.x = element_line(),
axis.line.y = element_line())+
scale_x_continuous(breaks = 1:13,
labels = df$label)+
labs(x=NULL,y=NULL,title = "AAA")
library(cowplot)
plot_grid(p1,p1,p1,p1,p1,p1,ncol=2,nrow=3)

需要示例数据的可以直接留言
欢迎大家关注我的公众号
小明的数据分析笔记本
网友评论