I have plotted positive values and negative values exactly as I would like them to be, legend included. I am now putting these together in one plot to create a single plot (I do not have enough points to link to this image). I am very pleased with this - except for the legend. The legend is sorted alphabetically which is not the my preferred order (the same order as the colour layers from top to bottom). I have tried different ways of trying to manually set the legend but all I have found so far works when plotting a single data frame and not two as I am.
It seems that using scale_colour_manual does not affect this type of plot, is there another way of doing this?
Below is a very simple working example that also gives the same behaviour described above.
data1 = data.frame(x = seq(0,20), y = c(1,4,-5,-9,-4,0,3,6,-4,3,-2,-5,8,2,1,6,7,-9,8,-4,0))
data2 = data.frame(x = seq(0,20), y = seq(0,20))
q = ggplot(NULL, aes(x = x, y = y))
q = q + geom_line(data = data1)
q = q + geom_line(data = data2)
Thanks, Jane
Thanks for the reply but I am still not getting the graph that I would like. Here is a link to closest that I have come to so far positive and negative values - legend not as required. For this plot I have used two separate data frames as I am using different geom_area
and geom_line
positions; for the positive part of the plot I am using:
geom_area(data = prod.data, position = "identity", alpha = 0.8)
geom_line(data = prod.data, position = "identity")
and for the negative part of the plot I am using:
geom_area(data = cons.data, position = "stack", alpha = 0.8)
geom_line(data = cons.data, position = "stack")
However, as discussed in the original question I seem to have no control over the order of the legend. I tried combining the data frames and set the order of the factor, here I used:
geom_area(position = "stack", alpha = 0.8)
geom_line(position = "stack")
and I have control over the legend order but the actual plot is not as I would like it. Here is the graph positive and negative values - graph not as required.
I'm having quantum mechanics flashbacks :-) so any further assistance is greatly appreciated.