r - 使用ggplot在分类X轴上连接来自不同组的点
问题描述
我正在尝试可视化三种方法之间 A、B 和 C 丰度的变化。A、B 和 C 也分为两组(“X”和“Y”)。我正在尝试用 ggplot 绘制这些图并将观察结果从一个方法连接到另一个方法,但我无法做到。这就是我所做的:
factor_1 <- c(rep(c("A", "B", "C"), times =6))
Abundance <- c(sample(x = 1:100, replace = T, size = 18))
factor_2 <- c(rep(c("X", "Y"), each = 3, times = 3))
factor_3 <- c(rep(c("Method 1", "Method 2", "Method 3"), each = 6))
datframe <- tibble(factor_1, factor_2, Abundance, factor_3)
datframe %>%
ggplot(aes(x = factor_3, y = Abundance, color = factor_2))+
geom_point() +
geom_line()
尝试按factor_1或factor_2 分组时,似乎将所有内容连接在一行中
datframe %>%
ggplot(aes(x = factor_3, y = Abundance, color = factor_2))+
geom_point() +
geom_line(group = c(factor_2))
datframe %>%
ggplot(aes(x = factor_3, y = Abundance, color = factor_2))+
geom_point() +
geom_line(group = c(factor_1))
即使我只绘制一行,R 也会抱怨说“geom_path:每个组只包含一个观察值。你需要调整组审美吗?” 并且不连接点。
datframe %>%
filter(factor_1 == "A", factor_2 == "X") %>%
ggplot(aes(x = factor_3, y = Abundance, color = factor_2))+
geom_point() +
geom_line()
我知道当 X 轴是一个连续变量时可以做到这一点,但是我没有看到它与一个分类变量。
这或多或少是我想要的。它甚至不需要进行彩色编码,因为我可以制作两张图,一张用于“X”,另一张用于“Y”。
预先感谢您的帮助。
解决方案
推荐阅读
- angular - Angular Notifier Not Syling Fix
- javascript - 如何获取附件的链接 Discord.js
- amazon-web-services - AWS SageMaker Groun Truth s3 无效
- python - CPython如何实现pop(0)?
- next.js - 如何创建聊天电子邮件通知
- c++ - 循环没有结束,我需要在代码中找到错误
- postgresql - 如何根据postgres中的开始和结束时间按小时划分持续时间?
- php - WooCommerce 结帐分散样式
- karate - 空手道名称不适用于嵌套功能文件调用
- linux - 带回退交换的 ram 驱动器