【问题标题】:lines to connect geom_jitter points in ggplot2连接ggplot2中geom_jitter点的线
【发布时间】:2020-01-06 22:41:11
【问题描述】:

我正在尝试连接来自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()

现在线和点没有连接。

【问题讨论】:

  • 我可能会误解这一点,但如果你想连接它们,那么为什么要使用 geom_jitter 而不是 geom_pointggplot(df, aes(x = x, y = y, col = z)) + geom_point() + geom_line()
  • geom_jitter 用于可视化分类变量的值分布。
  • 谢谢,@RonakShah。我的真实图表有误差线,我想显示它们。

标签: r ggplot2


【解决方案1】:
library(dplyr)
ggplot(df %>% mutate(x = jitter(x), y = jitter(y)), 
       aes(x = x, y = y, col = z)) + 
  geom_point() + 
  geom_line()

【讨论】:

  • 太棒了!非常感谢,@Jon Spring。就我而言,仅x = jitter(x) 就足够了。
【解决方案2】:

为您的数据添加抖动(一些偏差),然后绘制有偏差的数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-14
    • 1970-01-01
    • 2020-02-28
    相关资源
    最近更新 更多