r - 连接 ggplot2 中的 geom_jitter 点的线

标签 r ggplot2

我正在尝试连接来自 geom_jitter() 的点。

 df<-data.frame(x = c(1, 1, 2, 2, 3, 3), 
           y = c(1, 1, 2 , 3, 6, 5), 
           z = c("A", "B", "A", "B", "A", "B")) 
ggplot(df, aes(x = x, y = y, col = z)) + 
  geom_jitter() + 
  geom_line()

现在线和点没有连接。

最佳答案

library(dplyr)
ggplot(df %>% mutate(x = jitter(x), y = jitter(y)), 
       aes(x = x, y = y, col = z)) + 
  geom_point() + 
  geom_line()

enter image description here

关于r - 连接 ggplot2 中的 geom_jitter 点的线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57781581/

相关文章:

r - 使用 'write.table' 时出现额外字符问题

r - 更改复合图例标题

r - 在点图(ggplot)中添加线交叉因子

r - 将文本变量添加到 ggplot 条形图中的每个条形簇

r - GGP图: Different chart types in facets?

r - 如何在 facet_wrap 中使用 label_wrap_gen 和 as_labeller

从 R 中的多分隔 csv 文件读取数据

r - 如何使用 R 将多列堆叠为一列

r - 使条形图中的条具有相同的高度

r - 如何使用 ggplot2 删除特定值处的网格线?