用R语言画柱形图怎么让屁股朝右
发表于:2024-09-21 作者:千家信息网编辑
千家信息网最后更新 2024年09月21日,本篇内容主要讲解"用R语言画柱形图怎么让屁股朝右",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"用R语言画柱形图怎么让屁股朝右"吧!image.png因为A
千家信息网最后更新 2024年09月21日用R语言画柱形图怎么让屁股朝右
本篇内容主要讲解"用R语言画柱形图怎么让屁股朝右",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"用R语言画柱形图怎么让屁股朝右"吧!
因为A图的数据较多,我们来模仿B图,过程其实是一样的
左边两幅图是柱形图叠加误差线还叠加了散点图 最右侧的图可以用一个热图来画
最左边的屁股朝右的柱形图还是第一次画,查了一下可以借助
scale_y_reverse()
函数实现
set.seed(1234)
x<-seq(5,10,by=0.5)
df<-data.frame(`s__Klebsiella_phage_vB_KpnP_SU552A` = sample(x,10,replace = T),
`s__Escherichia_phage_ECBP5` = sample(x,10,replace = T),
`s__Clostridium_phage_phi8074-B1` = sample(x,10,replace = T),
check.names = F)
head(df)
宽格式转换为长格式df%>%
reshape2::melt() -> df1
分组求均值和标准差library(dplyr)
df%>%
reshape2::melt()%>%
group_by(variable)%>%
summarise(mean_value=mean(value),
sd_value=sd(value)) -> df2
柱形图叠加误差线和散点图ggplot()+
geom_col(data=df2,aes(x=variable,y=mean_value),
fill="#8babd3",
color="black")+
geom_errorbar(data=df2,aes(x=variable,
ymin=mean_value-sd_value,
ymax=mean_value+sd_value),
width=0.2)+
geom_jitter(data=df1,aes(x=variable,y=value),
width = 0.2,color="grey")
接下来就是调整坐标轴,让屁股朝右ggplot()+
geom_col(data=df2,aes(x=variable,y=mean_value),
fill="#8babd3",
color="black")+
geom_errorbar(data=df2,aes(x=variable,
ymin=mean_value-sd_value+0.001,
ymax=mean_value+sd_value),
width=0.2)+
geom_jitter(data=df1,aes(x=variable,y=value),
width = 0.2,color="grey")+
#scale_y_continuous(expand = c(0,0))+
theme_bw()+
coord_flip()+
scale_y_reverse(expand=c(0,0),
position="right")+
labs(x=NULL,y=NULL)
第二个柱形图也直接用这个数据画了ggplot()+
geom_col(data=df2,aes(x=variable,y=mean_value),
fill="#ffc080",
color="black")+
geom_errorbar(data=df2,aes(x=variable,
ymin=mean_value-sd_value+0.001,
ymax=mean_value+sd_value),
width=0.2)+
geom_jitter(data=df1,aes(x=variable,y=value),
width = 0.2,color="grey")+
scale_y_continuous(expand = c(0,0),
position = "right")+
theme_bw()+
coord_flip()+
labs(x=NULL,y=NULL)+
theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank())
接下来是构造最右侧的热图数据df3<-data.frame(x="A",
y=c("s__Klebsiella_phage_vB_KpnP_SU552A",
"s__Escherichia_phage_ECBP5",
"s__Clostridium_phage_phi8074-B1"),
group=c("f__Siphoviridae",
"f__Podoviridae",
"f__Podoviridae"))
ggplot(df3,aes(x=x,y=y))+
geom_tile(aes(fill=group),show.legend = F)+
labs(x=NULL,y=NULL)+
scale_x_discrete(expand = c(0,0))+
scale_y_discrete(expand = c(0,0))+
theme(panel.background = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank())+
scale_fill_manual(values = c("#c65911","#ffd965"))
最后是拼图library(patchwork)
p1+p2+p3+ggtitle("Bacteriophages")+
theme(plot.title = element_text(hjust=5))+
plot_layout(widths = c(1.2,1,0.2)) -> p
ggsave(filename = "Rplot10.pdf",
p,
width = 10,height = 3)
最终的结果如下
到此,相信大家对"用R语言画柱形图怎么让屁股朝右"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
屁股
数据
语言
叠加
接下来
内容
右侧
格式
误差
热图
学习
实用
更深
兴趣
函数
均值
坐标
坐标轴
实用性
实际
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络安全法修改案2020
称之为数据库的
两个网站公用数据库
怎么在系统里设置代理服务器
丹江口互联网软件开发不二之选
软件开发真实感受
华为服务器配置raid设置
江苏营销软件开发优势
问责条款 网络安全事故
sql数据库中数组格式化
sql恢复删除的数据库
数据库公司怎么赚钱
图数据库 作用是什么
时钟服务器管理制度
我的世界服务器2009
平台管理服务器代替nvr
软件开发的口号标语
计算机网络安全问题内容
有魂师生存的服务器名字
软件开发报价不同怎么样
海南安脉云网络技术有限公司
云存储服务器有多少ZB
服务器上网越来越慢
arma3怎么管理服务器
高并发 数据库读写
网络安全火
涉密软件开发管理服务
5g会让网络安全变的困难吗
网络安全专辑手抄报怎么画
日志写入数据库技巧