首页 > 解决方案 > 如何使用ggplot将两个r块合并在一起

问题描述

我有两个 r 块可以制作两个图表,但我想将它们保存在两个图表中,但将它们放入一个 r 块中,我该怎么做

accidents %>%
  filter(day_of_week != c("Sunday", "Saturday")) %>%
  ggplot(mapping = aes(x = time, fill=severity)) +
  geom_density(adjust = 2, alpha = 0.5) +
  labs(
    x = "time",
    y = "Density",
    title = "accidents in weekdays"
  )
accidents %>%
  filter(day_of_week == c("Sunday", "Saturday")) %>%
  ggplot(mapping = aes(x = time, fill=severity)) +
  geom_density(adjust = 2, alpha = 0.5) +
  labs(
    x = "time",
    y = "Density",
    title = "accidents in weekends"
  )

标签: rggplot2mergechunksgraphing

解决方案


将您的绘图输出到这样的对象

ggplot2 ()+ 等实验室 () -> p1

ggplot2 ()+ 等实验室 () -> p2

打印(p1)

打印(p2)


推荐阅读