ggplot tools ggpubr arrange
library(ggpubr) # ggpubr 是基于ggplot2开发,更便捷,使图满足论文出版的需要。
df<-iris colnames (df)<- paste0 ( "V" ,1:5) # paste0 连接符是空字符串,相比paste不能设置sep df |
1 2 3 4 5 | p1<- ggplot (df, aes (x=V1,y=V2))+ geom_point ( aes (color=V5))+ theme_bw () p1 p2<- ggplot (df, aes (x=V1,y=V3))+ geom_point ( aes (color=V5))+ theme_bw () p3<- ggplot (df, aes (x=V1,y=V4))+ geom_point ( aes (color=V5))+ theme_bw () ggarrange (p1,p2,p3,ncol=3) |
p1:
ggarrange(p1,p2,p3,ncol=3) # 注 Rstudio 缩略图坐标压缩不正常显示,zoom看正常,解决方法是ggsave可以保存正常图如ggsave("~/Downloads/ggarrange.png",ggarrange(p1,p2,p3,ncol=3))
备注 这里Rstudio右下角压缩不正常图 ,直接Export也是这种异常,需要ggsave
因为图例一致,可以共用图例,设置common.legend=T
参数ncol: 设置绘图网格的列数,number of columns in the plot grid.
1 | ggarrange (p1,p2,p3,ncol=3,common.legend = T) |
设置图例位置 legend = "right"
1 | ggarrange (p1,p2,p3,ncol=3,common.legend = T,legend = "right" ) |
1 2 | df$V6<- sample ( LETTERS [1:6],150,replace = T) df |
1 2 | p4<- ggplot (df, aes (x=V1,y=V2))+ geom_point ( aes (color=V6))+ theme_bw () p4 |
1 2 3 | p5<- ggplot (df, aes (x=V1,y=V3))+ geom_point ( aes (color=V6))+ theme_bw () p6<- ggplot (df, aes (x=V1,y=V4))+ geom_point ( aes (color=V6))+ theme_bw () ggarrange (p4,p5,p6,ncol=3,common.legend = T) #图例放在顶部,默认布局是3行3列 |
更改图例中顺序。
1 2 | p4<- ggplot (df, aes (x=V1,y=V2))+ geom_point ( aes (color=V6))+ theme_bw ()+ theme (legend.position = "top" ) #默认是如下顺序 p4 |
1 2 | p4<- ggplot (df, aes (x=V1,y=V2))+ geom_point ( aes (color=V6))+ theme_bw ()+ theme (legend.position = "top" )+ scale_color_discrete (guide= guide_legend (byrow=T)) p4 # 靠guide_legend 设置图例顺序 |
1 2 | p4<- ggplot (df, aes (x=V1,y=V2))+ geom_point ( aes (color=V6))+ theme_bw ()+ theme (legend.position = "top" )+ scale_color_discrete (guide= guide_legend (byrow = T,nrow=1)) p4 |
ggarrange
本文来自博客园,作者:BioinformaticsMaster,转载请注明原文链接:https://www.cnblogs.com/koujiaodahan/p/15862815.html
posted on 2022-02-04 14:50 BioinformaticsMaster 阅读(143) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了