如何用R语言ggplot2画折线图并添加误差线
本篇文章给大家分享的是有关如何用R语言ggplot2画折线图并添加误差线,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
成都创新互联公司一直在为企业提供服务,多年的磨炼,使我们在创意设计,全网整合营销推广到技术研发拥有了开发经验。我们擅长倾听企业需求,挖掘用户对产品需求服务价值,为企业制作有用的创意设计体验。核心团队拥有超过10年以上行业经验,涵盖创意,策化,开发等专业领域,公司涉及领域有基础互联网服务成都移动服务器托管、成都app软件开发公司、手机移动建站、网页设计、网络整合营销。
折线图添加误差线是非常常用的一种可视化方法,今天的推文介绍一下使用R语言的ggplot2作图的代码。模仿的是论文 Phased diploid genome assemblies and pan-genomes provide insights into the genetic history of apple domestication中的Figure3中的d图


数据保存为csv格式
df<-read.csv("line.csv",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)

以上就是如何用R语言ggplot2画折线图并添加误差线,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。
文章题目:如何用R语言ggplot2画折线图并添加误差线
网站路径:http://abwzjs.com/article/jdsggs.html