有没有办法根据数值为箱线图上的抖动点着色,例如:
ggplot(data, aes(y = y_var, x = x_var)) +
geom_jitter(size = 2, aes(color = ifelse(y_var < 5, "red", "black)))
我添加了这个不太有效的可重现示例(图上的颜色与抖动调用不对应):
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")))