scale_gradient {ggplot2}R Documentation

scale_gradient

Description

Smooth gradient between two colours

Usage

scale_colour_gradient(name=NULL, low="#3B4FB8", high="#B71B1A", space="rgb", breaks=NULL, labels=NULL, limits=NULL, trans="identity", alpha=1, ...)
scale_fill_gradient(name=NULL, low="#3B4FB8", high="#B71B1A", space="rgb", breaks=NULL, labels=NULL, limits=NULL, trans="identity", alpha=1, ...)

Arguments

name name of scale to appear in legend or on axis. Maybe be an expression: see ?plotmath
low colour at low end of scale
high colour at high end of scale
space colour space to interpolate through, rgb or Lab, see ?colorRamp for details
breaks numeric vector indicating where breaks should lie
labels character vector giving labels associated with breaks
limits numeric vector of length 2, giving the extent of the scale
trans a transformer to use
alpha alpha value to use for colours
... other arguments

Details

This page describes scale_gradient, see layer and qplot for how to create a complete plot from individual components.

Value

A layer

Author(s)

Hadley Wickham, http://had.co.nz/

See Also

Examples

## Not run: 
# It's hard to see, but look for the bright yellow dot 
# in the bottom right hand corner
dsub <- subset(diamonds, x > 5 & x < 6 & y > 5 & y < 6)
(d <- qplot(x, y, data=dsub, colour=z))
# That one point throws our entire scale off.  We could
# remove it, or manually tweak the limits of the scale

# Tweak scale limits.  Any points outside these
# limits will not be plotted, but will continue to affect the 
# calculate of statistics, etc
d + scale_colour_gradient(limits=c(3, 10))
d + scale_colour_gradient(limits=c(3, 4))
# Setting the limits manually is also useful when producing
# multiple plots that need to be comparable

# Alternatively we could try transforming the scale:
d + scale_colour_gradient(trans = "log")
d + scale_colour_gradient(trans = "sqrt")

# Other more trivial manipulations, including changing the name
# of the scale and the colours.

d + scale_colour_gradient("Depth")
d + scale_colour_gradient(expression(Depth[mm]))

d + scale_colour_gradient(limits=c(3, 4), low="red")
d + scale_colour_gradient(limits=c(3, 4), low="red", high="white")
# Much slower
d + scale_colour_gradient(limits=c(3, 4), low="red", high="white", space="Lab")
d + scale_colour_gradient(limits=c(3, 4), space="Lab")

# Can also make partially transparent
d + scale_colour_gradient(limits=c(3, 4), alpha=0.5)

# scale_fill_continuous works similarly, but for fill colours
(h <- qplot(x - y, data=dsub, geom="histogram", binwidth=0.01, fill=..count..))
h + scale_fill_continuous(low="black", high="pink", limits=c(0,3100))
## End(Not run)

[Package ggplot2 version 0.8.2 Index]