I used this Question (ggplot scale color gradient to range outside of data range) to create a gradient within a specific range but now I have the problem, that all colors outside these limits are grey. I mean, it is logic to me but I wanted to have those to have the same color as the closest point.
ggplot(data.frame(a=1:10), aes(1, a, color=a)) +
geom_point(size=6) +
scale_colour_gradientn(colours=c('red','yellow','green'), limits=c(2,8))
So the top points should be green and the lower point should be red as well.
So what I am looking for is a range like limits=c(<2,>8)
but I know this is not working
You can specify how to deal with out-of-bounds values via argument oob
; for example, scales::squish
"squishes" values into the range specified by limits
:
ggplot(data.frame(a=1:10), aes(1, a, color = a)) +
geom_point(size = 6) +
scale_colour_gradientn(
colours=c('red','yellow','green'),
limits=c(2,8),
oob = scales::squish);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With