我试图将每个蓝点与每组相应的红点连接起来。但是,我无法使用geom_segment
。求助。
repl <- data.frame(title = c("A", "B", "C", "A", "B", "C"), diff = c(10.06, -1.89, 12.79, 10.06, -1.89, 12.79), id = c(1:6), acc= c(43, 50, 44, 43, 50, 44), variable= c(rep("A", 3), rep("B", 3)), value=c(43,50,44,53,48,56))
ggplot(repl, aes(value, title, y=reorder(title, diff), group=variable, color=variable)) +
geom_point(size=2, shape=8)+
geom_segment(aes(xend=value, x=value, y=title, yend=title), col='gray')
对于每个组,应该有一条线连接水平线上的两个点,我应该怎么做?
答案 0 :(得分:1)
应该这样做。
ggplot(repl, aes(x = value, y = reorder(title, diff),
group = title, color = variable)) +
geom_point(size = 2, shape = 8)+
geom_line(col = 'gray')
修改强>
您想要的是按title
连接点,同时按variable
对其进行着色,从而group = title
和color = variable
美学。