I'm making a scatter plot and I'd like to specify the order of the text in the legend, as well as the colors. Using ggplot, the color order does not match the text order as written.
My Code:
MyX<-c(1,2,3,4,5)
MyY<-c(3,4,5,2,7)
MyCat<-c("Dark","Medium","DarkLight","LightDark","Light")
MyDF<-data.frame(MyX,MyY,MyCat)
ggplot(MyDF, aes(x=MyX, y=MyY, color=MyCat)) +
geom_point()+
xlab("Time") +
ylab("Num") +
scale_color_manual(breaks = c("Dark","DarkLight","Medium","LightDark","Light"),
values=c("red", "orange","yellow","cadetblue2","dodgerblue"))
I don't want the default order of the text in the legend, so I'd like to change the order to be:
"Dark","DarkLight","Medium","LightDark","Light"
I also want the colors to be in the gradient:
"red", "orange","yellow","cadetblue2","dodgerblue"
So that Dark = Red, DarkLight = orange, Medium = yellow, LightDark = cadetblue2, Light = blue.
Which is what I would assume would happen with above code. But as plotted the text does not match the color and I have:
Dark = Red, DarkLight = orange, Medium = Blue, LightDark = cadetblue2, Light = yellow.
Note- I have the same issue when using a color ramp:
gs.pal <- colorRampPalette(c("red","blue"),bias=.1,space="rgb")
+scale_color_manual(breaks = c("Dark","DarkLight","Medium","LightDark","Light"),
values=gs.pal(5))