怎样使用R语言ggplot2画柱形图
发表于:2025-12-03 作者:千家信息网编辑
千家信息网最后更新 2025年12月03日,这期内容当中小编将会给大家带来有关怎样使用R语言ggplot2画柱形图,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。今天要模仿的图片来自于论文 Core gut m
千家信息网最后更新 2025年12月03日怎样使用R语言ggplot2画柱形图image.png image.png 接下来是简单地美化,包括调整配色,扩大y轴范围,去掉灰色背景,柱子贴底,去掉图例,更改x和y轴的标题,添加总标题,添加辅助线,添加误差线等等。image.png image.png 接下来是美化:包括去掉背景,更改配色,调整x轴标签的角度等等image.png 最后是拼图
这期内容当中小编将会给大家带来有关怎样使用R语言ggplot2画柱形图,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
今天要模仿的图片来自于论文 Core gut microbial communities are maintained by beneficial interactions and strain variability in fish。期刊是 Nature microbiology
今天重复的图片是Figure3中的柱形图
首先是第一个小图:柱形图,误差棒,显著性P值
第一步是模拟数据读入数据数据是三列:第一列用来做X,第二列做Y,第三列做误差条
df1<-read.csv("Figure3_d.csv",header=T)
ggplot2基本的柱形图,利用分组信息填充颜色library(ggplot2)
ggplot(df1,aes(x=group,y=value))+
geom_col(aes(fill=group),color="black")
下面的代码就不详细介绍了,争取录制一期视频来介绍
ggplot(df1,aes(x=group,y=value))+
geom_hline(yintercept = 0.5,lty="dashed")+
geom_hline(yintercept = 1,lty="dashed")+
geom_col(aes(fill=group),color="black")+
theme_bw()+
theme(panel.background = element_blank(),
panel.grid = element_blank(),
plot.title = element_text(hjust=0.5),
legend.position = "none")+
scale_y_continuous(expand = c(0,0),
limits = c(0,1.5))+
scale_x_discrete(labels=c("Positive\ninteractions","Negative\ninteractions"))+
annotate("segment",x=1,y=0.8,xend=1,yend=1)+
annotate("segment",x=2,y=0.4,xend=2,yend=0.5)+
labs(x=NULL,
y="Absolute fold change\nin growth from co-cultures\ncompared to monocultures",
title = "Average growth fold change in\nco-cultures")+
annotate("segment",x=1.1,y=1.2,xend=1.9,yend=1.2)+
annotate("segment",x=1,y=1.15,xend=1.1,yend=1.2)+
annotate("segment",x=1.9,y=1.2,xend=2,yend=1.15)+
annotate("text",x=1.5,y=1.3,label="P=0.0006")+
scale_fill_manual(values = c("#ff8080","#90bff9"))
接下来是第二个小图:有正值和负值的柱形图
第一步还是构造数据x<-1:28
y<-sample(-100:150,28,replace = F)
df2<-data.frame(x,y)
df2$group<-ifelse(df2$y>0,"A","B")
基本的柱形图df2$x<-factor(df2$x)
ggplot(df2,aes(x,y))+
geom_col(aes(fill=group),color="black")
df2$group<-factor(df2$group,
labels = c("Synergistic interactions",
"Non-synergistic interactions"))
ggplot(df2,aes(x,y))+
geom_hline(yintercept = -50,lty="dashed")+
geom_hline(yintercept = 50,lty="dashed")+
geom_hline(yintercept = 100,lty="dashed")+
geom_col(aes(fill=group),color="black")+
theme_bw()+
theme(panel.background = element_blank(),
panel.grid = element_blank(),
axis.text.x = element_text(angle = 90,hjust=0.5,
vjust = 0.5),
plot.title = element_text(hjust = 0.5),
legend.position = "bottom",
legend.title = element_blank())+
scale_y_continuous(expand=c(0,0),
limits=c(-100,150),
breaks = c(-100,-50,0,50,100,150))+
labs(x="Pairwise interactions",
y="Percentage change from\nmonoculture",
title = "Synergistic versus non-synergistic\ninteractions")+
scale_fill_manual(values = c("#ff8080","#90bff9"))
library(cowplot)
pdf("Rplot11.pdf",width = 8,,height = 4)
plot_grid(p1,p2,ncol = 2,nrow=1,labels = c("d","e"))
dev.off()
上述就是小编为大家分享的怎样使用R语言ggplot2画柱形图了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。
数据
接下来
误差
语言
内容
图片
标题
背景
角度
分析
调整
显著
专业
中小
代码
信息
内容丰富
图例
就是
文章
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
表格汇总数据库设计
samp人多的服务器
根据网络安全法关键信息每年
sw 数据库遗失
香港免流服务器
机械零件软件开发图片
我的世界服务器纯生存开荒
知识产权软件开发商
山东春考网络技术和数字媒体
南京耐思特互联网络科技
开国大典课件软件开发
数据库公司怎么赚钱
网络安全的影响因素
网络技术的商业计划书
服务器端口需要配置吗
数据库大量优化
阿里云公共云服务器
戴尔服务器有没有管理口
测试服务器性能指标
天下捷融互联网科技小贷怎么样
山东春考网络技术和数字媒体
吉林运营网络安全工程平台资质
怎样清除数据库的空间
普通人群dgv数据库
x5无法连接服务器
网络安全设计标志
为什么要指定网络安全法
易爱网络技术有限公司怎么样
软件开发 pm 简历
奇峰网络技术