It's probably easiest to just create a new variable limit
in your data, where you save the necessary factors. Then you can just change the function to color=limit
.
Q[, "limit"] <- factor("below", levels=c("below", "between", "above"))
Q[Q[, "BACE"]>=0.32, "limit"] <- "between"
Q[Q[, "BACE"]>=0.4, "limit"] <- "above"
Then you just have to change the color=limit
and the scale_colour_manual
to
scale_colour_manual(values=c(between="#000000", above="#CC0000", below="#0066FF"))
EDIT: If you have missing values in the BACE
variable, you can change the code to the following:
Q[!is.na(Q[, "BACE"]), "limit"] <- factor("below",
levels=c("below", "between", "above"))
Q[which(Q[, "BACE"]>=0.32), "limit"] <- "between"
Q[which(Q[, "BACE"]>=0.4), "limit"] <- "above"