

I think you're going to need to add each line manual. Scale_colour_manual(values = my_col_scheme) Geom_point(aes(color = Anion, shape = Cation), size = 3, alpha = 0.4) + Scale_color_manual(name = "", values = c("red", 'blue'), I can get either the regression lines colored: part1 <. Probably because we're trying to mix geoms (but that's just a guess). I also tried using the suggestions in this post, but that didn't work. I couldn't find that webpage, but this post touches on the topic. I seem to recall reading that you cannot change scale_color_manual twice in a plot.
#Aesthetic color codes update
I don't think ggplot2 will let you change color twice and update the legend. NOTE: I changed color=NA to color="transparent", as color=NA (in version 2 of ggplot2) causes the points to disappear completely, even if you use a point with separate border and fill colors. I'm not totally happy with the legend, but it was the best I could come up with without resorting to special-purpose grobs. Finally, I overrode the colour legend in order to include the linetype in the colour legend, which allowed me to get rid of the redundant linetype legend.

I don't know why, but without fill="somecolor" the shape legend is blank. Note that I've set fill="black" for the shape legend, but it's showing up as gray. I'm not sure why, but without these overrides, the legends for fill and shape are blank. All the stuff inside guides() is to modify the legend.Add scale_shape_manual and set the values to 21 and 24 (filled circles and triangles, respectively).Add scale_fill_manual to set the colors of the points using the fill aesthetic.In scale_colour_manual, I've set the colors to blue and red, but you can, of course, set them to whatever you prefer.If you want a border, set it to whatever border color you prefer. That will get rid of the border around the points. Also, put colour="transparent" outside of aes. In geom_point, change colour aesthestic to fill.Shape = guide_legend(override.aes = list(shape=c(21,24), fill="black", size=3)),Ĭolour = guide_legend(override.aes = list(linetype=c("dotdash", "F1"))), Guides(fill = guide_legend(override.aes = list(colour=my_col_scheme, Scale_fill_manual(values = my_col_scheme) + Scale_colour_manual(values = c("blue", "red")) + Geom_point(aes(fill = Anion, shape = Cation), size = 3, alpha = 0.4, colour="transparent") + Stat_smooth(method = "lm", formula = y ~ x + 0,īreaks = c("hal", "non-hal"), labels = c("Halides", "Non-Halides")) + Here's an example, adapting code: ggplot(currDT, aes(x = EFP, y = SAPT), na.rm = TRUE) + Filled point markers are those numbered 21 through 25 (see ?pch). You can get separate color mappings for the lines and the points by using a filled point marker for the points and mapping that to the fill aesthetic, while keeping the lines mapped to the colour aesthetic. How can this be done in ggplot2? From the other questions I gathered I could specify each line manually, but I'd like to avoid that. Scale_linetype_manual(name = "", values = c("dotdash", "F1"),īreaks = c("hal", "non-hal"), labels = c("Halides", "Non-Halides")) Stat_smooth(method = "lm", formula = y ~ x + 0, aes(linetype = Halide, colour = Halide), Scale_colour_manual(values = my_col_scheme) + Geom_point(aes(colour = Anion, shape = Cation), size = 3, alpha = 0.4) + Here is some example code: icorr_elec <- ggplot(currDT, Oh and here is the colour scheme I'm using at the moment, you can use scale_colour_brewer to generate your own, I'm just including this for completeness. I usually have my data in a data.table, so you might find it helpful change that as well. Just do a currDT <- read.table("SO_data", sep = "|", header = TRUE, strip.white = TRUE) Here is a Dropbox link to some example data. I'd like these lines to use a different colour palette. I'm using stat_smooth to draw certain smoothing lines through the points, grouped by another factor.

I have a scatterplot (using geom_point) coloured by a factor, using a particular colour palette. My question is very similar to this and this and also this question.
