Is there a way to color the jitter points on a boxplot based on a numeric value, so for example:
ggplot(data, aes(y = y_var, x = x_var)) + geom_jitter(size = 2, aes(color = ifelse(y_var < 5, "red", "black)))
I've added this reproducible example that doesn't quite work (the colors on the plot don't correspond to the jitter call):
a <- rnorm(100, mean = 5, sd = 1)b <- as.factor(sample(0:1, 100, replace = TRUE))test_data <- data.frame(cbind(a,b))test_data$b <- as.factor(test_data$b)ggplot(test_data, aes(y = a, x = b)) + geom_boxplot()+ geom_jitter(aes(color = ifelse(a < 5, "red", "black")))