line_data <- data.frame(value = c(1,2), color = as.factor(c("blue", "green"))
plot1 <- plot1 +
geom_hline(aes(yintercept = value, colour = color), line_data, linetype = "dashed", size = 0.5)
The above is a snippet of my code. No matter what I assign to color column, it will be ignored. I can assign integers or continuous numbers. it will be ignored.
EDITED:
The reason is because plot1 already has a scale_color_manual added to it. Now the challenge becomes how to make it work without having to remove the scale_color_manual?
Please post reproducible code to help us answer your question. We don't know what
plot1is.Use
scale_colour_identityto tell ggplot2 to interpret the variable directly as a color:EDIT: To make a new color legend compatible with an existing one, re-specify
scale_colour_manual. You will still get the warningScale for 'colour' is already present. Adding another scale for 'colour', which will replace the existing scale., but it works: