
Centre a ggplot legend beneath the plot using cowplot
centre_legend_below.RdExtract the legend from a ggplot object and place it centred beneath the whole plot. (As opposed to centred under the axis area only.) If the cowplot package is not installed, the plot is returned unchanged.
Usage
centre_legend_below(p, rel_heights = c(1, 0.1))Value
If cowplot is installed, a cowplot object with the legend centred underneath the plot. Otherwise, the original ggplot object is returned unchanged.
Details
This function extracts the legend from the supplied ggplot object,
removes the legend from the plot itself, and then stacks the plot and
legend vertically using cowplot::plot_grid(). The relative
heights of the two components can be controlled via rel_heights.