Skip to content
Prev 385399 / 398506 Next

ggplot 3-color gradient scales

Hello,

Note that the midpoint argument can make a big difference. In the code 
below try commenting out the line where the default is changed.


f <- function(x){
   (x - min(x))/(max(x) - min(x))
}

library(ggplot2)

df1 <- iris[3:5]
names(df1)[1:2] <- c("x", "y")
df1$z <- ave(df1$y, df1$Species, FUN = f)

ggplot(df1) +
   geom_point( aes(x, y, color = z) ) +
   scale_color_gradient2(low = "red",
                         mid = "yellow",
                         high = "blue",
                         midpoint = 0.5
                         )

Hope this helps,

Rui Barradas


?s 04:43 de 24/08/20, Jeff Newmiller escreveu: