scale_colour_gradient2(..., low = muted("red"), mid = "white", high = muted("blue"),
midpoint = 0, space = "rgb", na.value = "grey50", guide = "colourbar")
scale_fill_gradient2(..., low = muted("red"), mid = "white", high = muted("blue"),
midpoint = 0, space = "rgb", na.value = "grey50", guide = "colourbar")
scale_color_gradient2(..., low = muted("red"), mid = "white", high = muted("blue"),
midpoint = 0, space = "rgb", na.value = "grey50", guide = "colourbar")
"colourbar" for
continuous colour bar, or "legend" for discrete
colour legend.discrete_scale to control name, limits,
breaks, labels and so forth.Diverging colour gradient
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))
d + scale_colour_gradient2()
# Change scale name d + scale_colour_gradient2(expression(sqrt(abs(x - y))))
d + scale_colour_gradient2("Difference\nbetween\nwidth and\nheight")
# Change limits and colours d + scale_colour_gradient2(limits=c(-0.2, 0.2))
# Using "muted" colours makes for pleasant graphics # (and they have better perceptual properties too) library(scales) # for muted d + scale_colour_gradient2(low="red", high="blue")
d + scale_colour_gradient2(low=muted("red"), high=muted("blue"))
# Using the Lab colour space also improves perceptual properties # at the price of slightly slower operation d + scale_colour_gradient2(space="Lab")
# About 5% of males are red-green colour blind, so it's a good # idea to avoid that combination d + scale_colour_gradient2(high=muted("green"))
# We can also make the middle stand out d + scale_colour_gradient2(mid=muted("green"), high="white", low="white")
# or use a non zero mid point (d <- qplot(carat, price, data=diamonds, colour=price/carat))
d + scale_colour_gradient2(midpoint=mean(diamonds$price / diamonds$carat))
# Fill gradients work much the same way p <- qplot(letters[1:5], 1:5, fill= c(-3, 3, 5, 2, -2), geom="bar") p + scale_fill_gradient2("fill")Mapping a variable to y and also using stat="bin". With stat="bin", it will attempt to set the y value to the count of cases in each group. This can result in unexpected behavior and will not be allowed in a future version of ggplot2. If you want y to represent counts of cases, use stat="bin" and don't map a variable to y. If you want y to represent values in the data, use stat="identity". See ?geom_bar for examples. (Deprecated; last used in version 0.9.2)
# Note how positive and negative values of the same magnitude # have similar intensity
scale_color_brewer,
scale_color_continuous,
scale_color_discrete,
scale_color_gradient,
scale_color_gradientn,
scale_color_grey,
scale_color_hue,
scale_colour_brewer,
scale_colour_continuous,
scale_colour_discrete,
scale_colour_gradient,
scale_colour_gradientn,
scale_colour_grey,
scale_colour_hue,
scale_fill_brewer,
scale_fill_continuous,
scale_fill_discrete,
scale_fill_gradient,
scale_fill_gradientn,
scale_fill_grey,
scale_fill_hue