I have a 5 data frames (actually one and 4 sub sets of the same with some filters), and the idea is to plot them according to colors and have corresponding colors on the legend. But in the legend the colors are mixed, the order of the names are kept. I am not sure how are they ordered but not according to my input.
My code is:
ggplot(regression_with_pred, aes(x= countF, y= countM)) +
geom_point(alpha = 0.5, size=0.1) +
geom_smooth(method = lm, se=F, color ="#e08214") +
geom_ribbon(aes(ymin=lwr, ymax=upr, fill="#e08214"), alpha = 0.2) +
ggtitle(samplename) +
theme_bw() +
geom_point(data=y_mers, aes(x= countF, y= countM, color = "y_mers"), alpha = 0.5, size=0.1) +
geom_point(data=x_mers, aes(x= countF, y= countM, color = "x_mers"), alpha = 0.5, size=0.1) +
geom_point(data=z_mers, aes(x= countF, y= countM, color = "z_mers"), alpha = 0.5, size=0.1) +
geom_point(data=w_mers, aes(x= countF, y= countM, color = "w_mers"), alpha = 0.5, size=0.1) +
scale_color_manual(name = "Kmer association",
values = c("y_mers" = "#053061", "x_mers" = "#b2182b", "z_mers" = "#2166ac", "w_mers"="#d6604d"),
labels = c("y_mers","x_mers","z_mers","w_mers")) +
scale_fill_identity()
It's wrong because "y_mers" should have the color of "x_mers", "x_mers" the color of "zmers", "zmers" the color of "w_mers", and "w_mers" the color of "y_mers".
Like this: The correct order