简体   繁体   English

连接 ggplot2 中 geom_jitter 点的线

[英]lines to connect geom_jitter points in ggplot2

I am trying to connect the points from geom_jitter() .我正在尝试连接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()

Now the lines and points are not connected.现在线和点没有连接。

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

在此处输入图片说明

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM