How to jitter both geom_line and geom_point by the same magnitude?

前端 未结 3 1008
刺人心
刺人心 2020-12-10 12:30

I have a ggplot2 linegraph with two lines featuring significant overlap. I\'m trying to use position_jitterdodge() so that they are more visible, b

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 13:22

    On July 2017, developpers of ggplot2 have added a seed argument on position_jitter function (https://github.com/tidyverse/ggplot2/pull/1996).

    So, now (here: ggplot2 3.2.1) you can pass the argument seed to position_jitter in order to have the same jitter effect in geom_point and geom_line (see the official documentation: https://ggplot2.tidyverse.org/reference/position_jitter.html)

    Note that this seed argument does not exist (yet) in geom_jitter.

    ggplot(data = df, aes(x = dimension, y = value,
                          shape = Time, linetype = Time, group = Time)) +
      geom_line(position = position_jitter(width = 0.25, seed = 123)) +
      geom_point(position = position_jitter(width = 0.25, seed = 123)) +
      xlab("Dimension") + ylab("Value")
    

提交回复
热议问题