Hi,
> at the moment I am using
>
> geom_line() +
> scale_colour_gradient(low = "green", high = "red")
>
> to color the line depending on value (on the Y Axis).
>
> I can't figure out how to have values from 0-49 (low (green)), 50-99
> (mid (yellow)), and 100 and above (high red) color the line in those
> three different colors accordingly.
>
> Gradient is not required but would be cool.
Without a gradient, I'd use cut to convert my
values into a factor and then scale_colour_manual to
set the colours.
With a gradient, I suggest scale_colour_gradient2
or playing with scale_colour_gradientn which might help
you get more yellow values and a gradient.
TBL<-tibble(x=0:150,y=0:150)
TBL <- TBL %>%
mutate(yf = cut(y, breaks = c(-Inf, 49 , 99, Inf),
labels = c('Low', 'Medium', 'High')))
p1 <- ggplot(data = TBL, aes(x = x, y = y, colour = yf)) +
geom_line() +
scale_colour_manual(values = c('red', 'yellow', 'green'))
p2 <- ggplot(data = TBL, aes(x = x, y = y, colour = y)) +
geom_line() +
scale_colour_gradient2(low = 'red', mid = 'yellow',
high = 'green', midpoint = mean(0:150)
Hope this helps,
Ron.