Skip to contents

Create a legend that explains the features of a boxplot. Can be added easily to existing ggplots using plot_grid or plot_arithmetic.

Usage

ggplot_box_legend(
  font_family = "OpenSansCondensed_TWRI",
  point_label = " - Measured values"
)

Arguments

font_family

defaults to "OpenSansCondensed_TWRI". Can be modified to any locally installed font.

point_label

character string - how you want to label to point in a legend. If you overlay measured points in the box plot, " - Measured values" is appropriate. If the points only indicate outliers, " - values outside the\ninterquartile range" is appropriate. This can be custoimized as necessary. Use "\n" to indicate where a line break should occur.

Value

a ggplot object

Author

Laura DeCicco

Examples

library(ggplot2)
library(cowplot)
ggplot(dissolved_oxygen) +
  geom_boxplot(aes(as.factor(station_id),
                   average_do,
                   group = station_id)) +
  geom_jitter(aes(as.factor(station_id),
                  average_do,
                  group = station_id),
               width = 0.1, alpha = 0.25) +
 theme_TWRI_print() -> p1
file <- tempfile(fileext = '.png')
ragg::agg_png(file)
plot_grid(p1, ggplot_box_legend(), rel_widths = c(2,1))
dev.off()
#> agg_png 
#>       2