I tried several suggestions based on a few posts here, as well as reading the ggplot2 documentation, but this question is a little different and I haven't found a solution yet.
Here's a snippet of code to make the molten data frame look like the one I'm working with:
a <- c(1,2,3,4,5,6,1,2,3,4,5,6) b <- c("loss", "draw", "win", "draw", "loss", "win", "loss", "draw", "win", "draw", "loss", "win") c <- c(2,3,5,4,4,5,4,4,3,5,2,4) d <- c(rep("x", 6), rep("y", 6)) temp <- data.frame(a,b,c,d)
I want to create a scatter plot with b on the x-axis, c on the y-axis, with points on the x-axis, grouped by d, and the lines between them, grouped by a. If we start by simply placing the points on the chart, it will work out fine:
ggplot(temp, aes(x=b, y=c, fill=d, colour=d))+ geom_point(position=position_jitterdodge())
This is the point I get, and this is how I want it to look. The points are color coded according to the coefficient d, and in addition, they tremble on one side, so that x is on the left and y is on the right.
Now all I want is to connect the dots with the lines according to the coefficient a. This is the incorrect version I made in MS Paint , how it should look. Adding geom_line and setting the geom_line group to should work ...
ggplot(temp, aes(x=b, y=c, fill=d, colour=d))+ geom_point(position=position_jitterdodge())+ geom_line(aes(group=a),position=position_jitterdodge())
... but it is not. The lines he creates are the correct length to connect the correct points, but they barely touch them, it looks like they are on a graph at random. I would add another screenshot, but I don't have privileges yet.
Also, if I change the groupโs aesthetics to a general aesthetics, for example:
ggplot(temp, aes(x=b, y=c, fill=d, colour=d, aes(group=a)))+ geom_point(position=position_jitterdodge())+ geom_line(position=position_jitterdodge())
... then the points switch so that they are in the wrong position. And in any case, the lines are still not completely connected with the dots.
I also tried to specify the width and jitter.width values โโat position_jitterdodge (), and the lines and dots still did not connect properly. I also read the ggplot2 documentation, a few previous stackoverflow related questions, and tried out most combinations of position_jitter, position_dodge, geom_jitter, etc., but no luck so far.
Any help would be greatly appreciated.