I have been trying for hours to adjust the title of my legend in a ggplot2
line plot, but when I do I get a 'ghost legend' appearing below the real one. I'm using the following code to adjust parts of my legend (coluor, line type and symbol in order):
scale_color_manual(values = c("#FF6600", "green4", "#0099FF")) +
scale_linetype_manual(values=c("solid", "solid", "solid")) +
scale_shape_manual(values = c(16, 16, 16)) +
This comes up with a lovely legend matching my graph. However, when I try to add a title with this code:
labs(linetype='title')+
I get another legend appear below (so both are on the plot at the same time), with the correct title but none of the previous formatting. Obviously I'm coding a separate legend, but I can't fix it!
Also, the real title I want to give my legend requires a subscript '2' for CO2, and I've used the following to account for that in other titles:
expression(CO[2]~concentration~(ppm))
Thought I'd mention that just in case it changes anything.
Aaaaand while I'm at it, I also want to change the legend orientation to being horizontal rather than a vertical list, and shift it to a corner of the plot space (tried legend.position = c(0.9, 0.8)
which has worked before but not in this case).
My problem is that as I try each new thing, the errors compound and I can't move forward.
I realise this post is far from elegant, but any help would be greatly appreciated. I'm sorry I have not provided any example code, I'm an R newbie and totally swimming.
Thanks in advance!