r - R- ggplot:一个坐标系中的五个图
问题描述
一小时前我问了类似的问题,得到了一些不错的答案,但不是我要找的答案,可能是因为我的问题没有以正确的方式提出。这就是我再次发布它的方式,我在 ggplot 的帮助下在我的 R-Script 中绘制了不同的图表。为了比较它们,我需要将它们整合到一个图表中。
这是我当前的单图代码:
p1 <- ggplot(merch42, aes(x = day_code, y = avg_logistic_review_score, col = "red"))+ geom_smooth(method = "loess", span = 1/25, col = "red")
p2 <- ggplot(merch323, aes(x = day_code, y = avg_logistic_review_score, col = "blue"))+
geom_smooth(method = "loess", span = 1/25, col = "blue")
p3 <- ggplot(merch24, aes(x = day_code, y = avg_logistic_review_score, col = "green"))+
geom_smooth(method = "loess", span = 1/25, col = "green")
p4 <- ggplot(merch180, aes(x = day_code, y = avg_logistic_review_score, col = "yellow"))+
geom_smooth(method = "loess", span = 1/25, col = "yellow")
p5 <- ggplot(merch505, aes(x = day_code, y = avg_logistic_review_score, col = "merch505"))+
geom_smooth(method = "loess", span = 1/25, col = "black")
有人知道这是如何工作的吗?非常感谢:)菲尔
在这里,我已经在一页上对它们进行了比较。现在我需要在坐标系统中集成所有内容。
解决方案
考虑堆叠(即行绑定)所有数据帧,为每个数据帧添加一个指标变量,如类型,然后使用映射到指标变量的颜色进行绘图,甚至定义手动颜色:
final_df <- rbind(transform(merch42, type = "merch42"),
transform(merch323, type = "merch323"),
transform(merch24, type = "merch24"),
transform(merch180, type = "merch180"),
transform(merch505, type = "merch505"))
ggplot(final_df, aes(x = day_code, y = avg_logistic_review_score, color = type)) +
geom_smooth(method = "loess", span = 1/25) +
scale_color_manual(values = c("red", "blue", "green", "yellow", "black"))
推荐阅读
- git - 有没有办法防止 git 推送/拉取文件更新但将其保留在版本控制中?
- javascript - 有没有办法在 JavaScript 中有一个不和谐的机器人,在 python 中有一些命令?
- javascript - 如何在树状结构中搜索过滤器?
- azure - 即使“始终开启”,在 ASP.NET Core API 应用程序中响应第一个请求也需要 5 秒以上
- javascript - $.getJSON() 调用在 chrome 中极度延迟
- selenium - 在 Excel 中,默认情况下将“TRUE”视为布尔值“TRUE”,这使我的 selenium 代码失败
- mysql - Laravel Query Builder SUM 与 where 子句
- python - 在另一个类中创建一个类对象
- python - 可以在大学集群上导入 rpy2 但不能导入 rpy2.objects
- javascript - 如何使用jquery从倒计时的前几秒中获取变量的值?