I\'m trying to plot three datasets onto the same graph. One dataset should appear on the graph as just a set of unconnected points, whereas the other two should appear as co
The trick is that each layer can have its own dataset. So you have to subset the data to exclude L1=="p1"
from the data provided to geom_line
:
ggplot(zz, aes(x, y=value, color=L1)) +
geom_point() +
geom_line(data=zz[zz$L1!="p1", ]) +
scale_color_manual("Dataset",
values = c("p1" = "darkgreen", "p2" = "blue", "p3" = "red"))
You can feed a different dataset into each geom. So you can pass in a dataset excluding p1 into the geom_line layer. Something like this should work:
ggplot(zz, aes(x, value, color = L1)) +
geom_point() +
geom_line(data = subset(zz, L1 %in% c("p2", "p3")), aes(group = L1)) +
scale_color_manual("Dataset", values = c("p1" = "darkgreen", "p2" = "blue", "p3" = "red"))