I am trying to plot data points with three different colors for three value ranges. For example:
library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) + geom_point(a
You need to cut
your values into intervals:
library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
geom_point(aes(colour = cut(qsec, c(-Inf, 17, 19, Inf))),
size = 5) +
scale_color_manual(name = "qsec",
values = c("(-Inf,17]" = "black",
"(17,19]" = "yellow",
"(19, Inf]" = "red"),
labels = c("<= 17", "17 < qsec <= 19", "> 19"))