R语言中的图片布局设置

R语言中的图片布局是个问题,下面是对图片布局设置的方法。

python 复制代码
library(ggplot2)

p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)
p4 <- ggplot(mtcars) + geom_bar(aes(carb))
p5 <- ggplot(mtcars) + geom_violin(aes(cyl, mpg, group = cyl))

# The plots are layed out automatically by default
p1 + p2 + p3 + p4 + p5

# Use parentheses to group plots
(p1 + p2)/ p3 / p4


# Use byrow to change how the grid is filled out 
# byrow = FALSE表示按照列来进行排序
p1 + p2 + p3 + p4 + p5 + plot_layout(byrow = FALSE)

# Change the grid dimensions
# 第二列宽度是第一列的两倍,withths是相对高度和宽度
p1 + p2 + p3 + p4 + p5 + plot_layout(ncol = 2, widths = c(1, 2))

# Define layout at different nesting levels
# 三个维度,第一行p1p2,然后再规定p3p4在同一列,然后p5的高度是相对的两倍
p1 +
  p2 +
  (p3 +
     p4 +
     plot_layout(ncol = 1)
  ) +
  p5 +
  plot_layout(widths = c(2, 1))

# Complex layouts can be created with the `design` argument
# area(t, l, b = t, r = l) tb为上下边界, lr为左右边界
design <- c(
  area(1, 1, 2),
  area(1, 2, 1, 3),
  area(2, 3, 3),
  area(3, 1, 3, 2),
  area(2, 2)
)

plot(design)  # Show the layout to make sure it looks as it should
p1 + p2 + p3 + p4 + p5 + plot_layout(design = design)


# The same can be specified as a character string:
# 和上面的效果一样,数字相同就是占据同样的位置
design <- "
  122
  153
  443
"


#plot(design)  
p1 + p2 + p3 + p4 + p5 + plot_layout(design = design)

# Areas can be left empty
# When using strings to define the design `#` can be used to denote empty
# areas
design <- "
  1##
  123
  ##3
"
p1 + p2 + p3 + plot_layout(design = design)

# Use guides="collect" to remove duplicate guides
p6 <- ggplot(mtcars) + geom_point(aes(mpg, disp, color=cyl))
p7 <- ggplot(mtcars) + geom_point(aes(mpg, hp, color=cyl))
p6 + p7 + plot_layout(guides='collect')

# Guide position must be applied to entire patchwork
p6 + p7 + plot_layout(guides='collect') &
  theme(legend.position='bottom')
相关推荐
薛定谔的猫喵喵7 小时前
基于PyQt5的视频答题竞赛系统设计与实现
开发语言·qt·音视频
岱宗夫up7 小时前
Python 数据分析入门
开发语言·python·数据分析
码界筑梦坊7 小时前
325-基于Python的校园卡消费行为数据可视化分析系统
开发语言·python·信息可视化·django·毕业设计
多恩Stone7 小时前
【RoPE】Flux 中的 Image Tokenization
开发语言·人工智能·python
李日灐7 小时前
C++进阶必备:红黑树从 0 到 1: 手撕底层,带你搞懂平衡二叉树的平衡逻辑与黑高检验
开发语言·数据结构·c++·后端·面试·红黑树·自平衡二叉搜索树
Risehuxyc8 小时前
备份三个PHP程序
android·开发语言·php
lly2024068 小时前
PHP Error: 常见错误及其解决方法
开发语言
网安墨雨8 小时前
Python自动化一------pytes与allure结合生成测试报告
开发语言·自动化测试·软件测试·python·职场和发展·自动化
毕设源码李师姐8 小时前
计算机毕设 java 基于 java 的图书馆借阅系统 智能图书馆借阅综合管理平台 基于 Java 的图书借阅与信息管理系统
java·开发语言·课程设计
忆~遂愿8 小时前
Runtime 上下文管理:计算实例的生命周期、延迟最小化与上下文切换优化
java·大数据·开发语言·人工智能·docker