Learn R Programming

ggplot2 (version 0.9.0)

guides: Set guides for each scale.

Description

Guides for each scale can be set in call of scale_* with argument guide, or in guides.

Usage

guides(...)

Arguments

...
List of scale guide pairs

Value

  • A list containing the mapping between scale and guide.

See Also

Other guides: guide_colorbar, guide_colourbar, guide_legend

Examples

Run this code
# ggplot object

dat <- data.frame(x = 1:5, y = 1:5, p = 1:5, q = factor(1:5),
 r = factor(1:5))
p <- ggplot(dat, aes(x, y, colour = p, size = q, shape = r)) + geom_point()

# without guide specification
p

# Show colorbar guide for colour.
# All these examples below have a same effect.

p + guides(colour = "colorbar", size = "legend", shape = "legend")
p + guides(colour = guide_colorbar(), size = guide_legend(),
  shape = guide_legend())
p +
 scale_colour_continuous(guide = "colorbar") +
 scale_size_discrete(guide = "legend") +
 scale_shape(guide = "legend")

# Guides are integrated where possible

p + guides(colour = guide_legend("title"), size = guide_legend("title"),
  shape = guide_legend("title"))
# same as
g <- guide_legend("title")
p + guides(colour = g, size = g, shape = g)

p + opts(legend.position = "bottom")

# position of guides

p + opts(legend.position = "bottom", legend.box = "horizontal")

Run the code above in your browser using DataLab