Part 63 Legend guides
There are four styles of legend guides available:
guide_legend()
- Basic legend guide.
- Use this one most of the time.
guide_bins()
- Use if you’ve got binned scales.
guide_colorbar()
- Nicely show a continuous color gradient.
guide_colorsteps()
- Use with binned color/fill scales.
- Can also be useful if you have continous scales, but want to pick out useful reference levels.
<- p +
p1 guides(
colour = guide_legend(title = "legend"),
size = "none",
shape = "none"
)<- p +
p2 guides(
colour = guide_bins(title = "bins"),
size = "none",
shape = "none"
)<- p +
p3 guides(
colour = guide_colorbar(title = "colorbar"),
size = "none",
shape = "none"
)<- p +
p4 guides(
colour = guide_colorsteps(title = "colorsteps"),
size = "none",
shape = "none"
)
+ p2 + p3 + p4 p1
63.1 Legend arguments
title
- Set the title of the legend guide
- Also impacts legend merging
direction
"vertical"
or"horizontal"
nrow
andncol
- Control number of rows and columns of legend
reverse
TRUE
orFALSE
: Should the order of the legend values be reversed?
order
- If multiple legend guides are shown separately, what order should they appear in?
- A number between 1 and 99
To place the legend somewhere other than the right side, add theme(legend.position = "bottom")
to the plot:
+
p guides(
colour = guide_legend(title = "title"),
size = guide_legend(title = "title"),
shape = guide_legend(title = "title")
+
) theme(legend.position = "bottom")