0

I have two or more data sources. Each has different colour groups. I do

pPrice = ggplot() +
    geom_step(data = data1, aes(x=Time, y=v, colour=TYPE)) +
    geom_point(data = data2, aes(x=Time, y=x, colour=g), shape = 18, size = 5)
pPrice

And I get:

data1 -> geom_line, data2 -> geom_point

I want to seperate the line and the dots into two legends. The first has a line in it with the corresponding colors and the second has the diamonds with the corresponding colors. My full graph contains even more layers with different data sets, an extra set with geom_points and 'x's instead of diamonds and colour groups. I would like to sperate those as well.

Courvoisier
  • 904
  • 12
  • 26
  • 1
    ggplot2 does not support more than one color legend (rightly so). Maybe you can make do with a `color` and a `fill` legend (use point symbols that have a fill color), but more is not sensible nor possible without hacking at the underlying grid level. You could create separate plots, extract the legends you want and add them to the final plot using `grid.arrange`, i.e., use [this strategy](http://stackoverflow.com/a/28594060/1412059). – Roland Oct 27 '16 at 10:43
  • Thanks @Roland. The separate plot solution is a good idea. But a lot of work needs to be done to guarantee color separation. btw, why do you say "rightly so"? – Courvoisier Nov 10 '16 at 10:22

0 Answers0