I have this data:
df <- data.frame(x = 1:10,
y = 1:10,
value = c(seq(from = 0.5, to = 3.2, length.out = 9), Inf))
which I want to plot with a gradient colour scale highlighting three break values:
breaks <- c(0.5,1,3.2)
I want the white
colour to highlight my middle breaking value (that is 1
) and then the other two to increase in intensity as they reach the two tails of the distribution. Yet this will plot
require(ggplot)
ggplot(df, aes(x,y,colour=value)) + geom_point(size=10) +
scale_colour_gradientn(colours = c("red","white","blue"),
breaks = breaks, labels = format(breaks))
with white
centered on the mean/median value (1.85
). I don't understand what's the point in declaring break points then.
You could use scale_colour_gradient2
instead of scale_colour_gradientn
:
ggplot(df, aes(x,y,colour=value)) +
geom_point(size=10) +
scale_colour_gradient2(low = "red", mid = "white", high = "blue", midpoint = 1, breaks = breaks) +
theme_bw()
this gives:
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