Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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_colourbar(), guide_legend()

Examples

# 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")

 # Remove some guides
 p + guides(colour = "none")
 p + guides(colour = "colorbar",size = "none")

# 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 + theme(legend.position = "bottom")

# position of guides

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

# Set order for multiple guides
ggplot(mpg, aes(displ, cty)) +
  geom_point(aes(size = hwy, colour = cyl, shape = drv)) +
  guides(
   colour = guide_colourbar(order = 1),
   shape = guide_legend(order = 2),
   size = guide_legend(order = 3)
 )

animint2

Animated Interactive Grammar of Graphics

v2020.9.18
GPL-3
Authors
Toby Hocking [aut, cre] (Original animint code), Hadley Wickham [aut] (Forked ggplot2 code), Winston Chang [aut] (Forked ggplot2 code), RStudio [cph] (Forked ggplot2 code), Nicholas Lewin-Koh [aut] (hexGrob), Martin Maechler [aut] (hexGrob), Randall Prium [aut] (cut_width), Susan VanderPlas [aut] (Animint GSOC 2013), Carson Sievert [aut] (Animint GSOC 2014), Kevin Ferris [aut] (Animint GSOC 2015), Jun Cai [aut] (Animint GSOC 2015), Faizan Khan [aut] (Animint GSOC 2016-2017), Vivek Kumar [aut] (Animint GSOC 2018), Himanshu Singh [aut] (Animint2 GSoC 2020)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.