【问题标题】:how to merge two r chunks together using ggplot如何使用ggplot将两个r块合并在一起
【发布时间】:2021-02-22 23:38:04
【问题描述】:

我有两个 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"
  )

【问题讨论】:

  • 我认为filter 条件不正确
  • 如果您将两个图的代码保存在 Markdown 中的同一块中,它将打印两个图。

标签: r ggplot2 merge chunks graphing


【解决方案1】:

将绘图输出到这样的对象

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

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

打印(p1)

打印(p2)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-23
    • 2015-09-08
    • 2011-01-22
    • 2018-08-13
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多