[英]How to use multiple colors in a single plot in R?
这是一个ggplot解决方案:
library(tidyverse)
df <-
x %>%
enframe(name = "Index") %>%
mutate(
color = case_when(
Index <= 2000 ~ "green",
Index <= 4000 ~ "red",
TRUE ~ "blue"
)
)
df %>%
ggplot(aes(x = Index, y = value, color = color)) +
geom_line(show.legend = FALSE) +
scale_color_manual(values = c("blue" = "blue", "green" = "green", "red" = "red"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.