View source: R/guide-legend-group.R
guide_legend_group | R Documentation |
This legend resembles ggplot2::guide_legend()
, but has the ability to
keep groups in blocks with their own titles.
guide_legend_group(
key = "group_split",
title = waiver(),
override.aes = list(),
nrow = NULL,
ncol = NULL,
theme = NULL,
position = NULL,
direction = NULL,
order = 0
)
key |
A group key specification. Defaults to
|
title |
A |
override.aes |
A named |
nrow , ncol |
A positive |
theme |
A |
position |
A |
direction |
A |
order |
A positive |
A <GuideLegend>
object.
Other standalone guides:
guide_axis_base()
,
guide_axis_dendro()
,
guide_axis_nested()
,
guide_circles()
,
guide_colbar()
,
guide_colring()
,
guide_colsteps()
,
guide_legend_base()
,
guide_legend_cross()
Other legend guides:
guide_legend_base()
,
guide_legend_cross()
# Standard plot for selection of `msleep`
df <- msleep[c(9, 28, 11, 5, 34, 54, 64, 24, 53), ]
p <- ggplot(df) +
aes(bodywt, awake, colour = paste(order, name)) +
geom_point()
# By default, groups are inferred from the name
p + guides(colour = "legend_group")
# You can also use a look-up table for groups
# The lookup table can be more expansive than just the data:
# We're using the full 'msleep' data here instead of the subset
lut <- key_group_lut(msleep$name, msleep$order)
p + aes(colour = name) +
guides(colour = guide_legend_group(key = lut))
# `nrow` and `ncol` apply within groups
p + guides(colour = guide_legend_group(nrow = 1))
# Groups are arranged according to `direction`
p + guides(colour = guide_legend_group(ncol = 1, direction = "horizontal")) +
theme(legend.title.position = "top")
# Customising the group titles
p + guides(colour = "legend_group") +
theme(
legendry.legend.subtitle.position = "left",
legendry.legend.subtitle = element_text(
hjust = 1, vjust = 1, size = rel(0.9),
margin = margin(t = 5.5, r = 5.5)
)
)
# Changing the spacing between groups
p + guides(colour = "legend_group") +
theme(legendry.group.spacing = unit(0, "cm"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.