Lets say I've made three plots with this code:
library(ggplot2)
ggplot(mtcars, aes(hp, wt, color = as.factor(cyl))) + geom_point() + scale_color_manual(limits = c("4", "6", "8"), breaks = c("4", "6", "8"), values = c("red", "blue", "green"))
ggplot(mtcars, aes(hp, mpg, color = as.factor(cyl))) + geom_point() + scale_color_manual(limits = c("4", "6", "8"), breaks = c("4", "6", "8"), values = c("red", "blue", "green"))
ggplot(mtcars, aes(hp, drat, color = as.factor(cyl))) + geom_point() + scale_color_manual(limits = c("4", "6", "8"), breaks = c("4", "6", "8"), values = c("red", "blue", "green"))
How can I convert this part of the code to a function called: scale_color_manual(limits = c("4", "6", "8"), breaks = c("4", "6", "8"), values = c("red", "blue", "green"))?