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.
p1 <- p +
guides(
colour = guide_legend(title = "legend"),
size = "none",
shape = "none"
)
p2 <- p +
guides(
colour = guide_bins(title = "bins"),
size = "none",
shape = "none"
)
p3 <- p +
guides(
colour = guide_colorbar(title = "colorbar"),
size = "none",
shape = "none"
)
p4 <- p +
guides(
colour = guide_colorsteps(title = "colorsteps"),
size = "none",
shape = "none"
)
p1 + p2 + p3 + p463.1 Legend arguments
title
- Set the title of the legend guide
- Also impacts legend merging
direction
"vertical"or"horizontal"
nrowandncol
- Control number of rows and columns of legend
reverse
TRUEorFALSE: 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")