2

I'm trying to connect each blue point with its corresponding red point per group. However, I have trouble using geom_segment. Thx for help.

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') 

enter image description here

For each group there should be a line connecting the two points on the horizontal, how should I do that?

1
  • Do you want to connect lines within variable or between? Commented Jul 26, 2017 at 12:13

1 Answer 1

5

This should do.

ggplot(repl, aes(x = value, y = reorder(title, diff), group = title, color = variable)) + geom_point(size = 2, shape = 8)+ geom_line(col = 'gray') 

EDIT:

What you want is to connect points by title while coloring them by variable hence the group = title and color = variable aesthetic.

Sign up to request clarification or add additional context in comments.

1 Comment

Please add explanation how you solved the problem given OP's code.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.