r - 如何使用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"
)
解决方案
将您的绘图输出到这样的对象
ggplot2 ()+ 等实验室 () -> p1
ggplot2 ()+ 等实验室 () -> p2
打印(p1)
打印(p2)
推荐阅读
- java - 未知实体类型的通用 LocalDate JPA 标准构建
- java - 将字符串变量用作“if”条件的一部分时遇到问题
- excel - 如何正确实现 range.find 文本部分匹配搜索?
- r - R Shiny - 将反应数据传递给模型的问题
- sql - 识别相互指向的数据库记录
- database - 指针引用上具有 $group 和 $count 的 MongoDB 聚合管道返回错误数据
- c++ - 使用 CMake 和 Make 编译时出现 OpenCV 库错误:找不到 -lopencv_bgsegm
- javascript - 在 Html 画布上放置蓝色色调的快速方法
- javascript - 读取 CSV 等数组的数组
- sapui5 - 如何从 OData 元数据创建本地空 JSON 模型