r - ggplot: gradient scale to diverge on specific break -
i have data
df <- data.frame(x=1:10, y=1:10, value = c(seq(from=0.5,to=3.2,length.out=9),inf))
which want plot gradient colour scale highlighting 3 break values:
breaks <- c(0.5,1,3.2)
i want white
colour highlight middle breaking value (that 1
) , other 2 increase in intensity reach 2 tails of distribution. yet 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 mean/median value (1.85
). don't understand what's point in declaring break points then.
you 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:
Comments
Post a Comment