scale_colour_gradient(low="red", high="blue")
generates a colour gradient that looks mostly red. I expected red-violet-blue
with violet at in the middle but I got red-still_red-violet-blue
How can I get a gradient with violet centered?
scale_colour_gradientn(colours=c("red","violet","blue"))
library(ggplot2)
dsub <- subset(diamonds, x > 5 & x < 6 & y > 5 & y < 6)
dsub$diff <- with(dsub, sqrt(abs(x-y))* sign(x-y))
(d <- qplot(x, y, data=dsub, colour=diff))
max_val <- max(abs(dsub$diff))
values <- seq(-max_val, max_val, length = 3)
d + scale_colour_gradientn(colours=c("red","violet","blue"),
values = values, rescaler = function(x, ...) x, oob = identity)
and as said in comment , more simple with scale_colour_gradient2
d + scale_colour_gradient2(low='red',mid='violet',high='blue')
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