add_facet_borders: Adds borders around panels and strips

View source: R/add-facet-borders.R

add_facet_bordersR Documentation

Adds borders around panels and strips

Description

This is a convenience function to add borders around panels and strips in ggplot2. All it does it modify the panel.border and strip.background theme elements to have the same specified color. Credit to the cowplot package back for the idea. I only added the extra strip.background border because I think it looks better.

Usage

add_facet_borders(color = "grey70", colour)

Arguments

color, colour

The color of the border.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

# Load the default font (Roboto Condensed)
extrafont::loadfonts(quiet = TRUE)

p <- penguins %>%
  filter(!is.na(bill_length_mm)) %>%
  ggplot(aes(x = bill_length_mm, y = bill_depth_mm, color = species)) +
  geom_point(aes(shape = species), size = 3, alpha = 0.7) +
  geom_smooth(method = "lm", formula = "y ~ x", se = FALSE) +
  scale_color_brewer(palette = "Set1") +
  labs(
    title = "Penguin bill dimensions",
    subtitle = "Bill length and depth for different penguin species",
    x = "Bill length (mm)", y = "Bill depth (mm)",
    color = "Penguin species", shape = "Penguin species",
    caption = "Data from the palmerpenguins package"
  ) +
  facet_wrap(~species, nrow = 1)

p + theme_td() + add_facet_borders()

taylordunn/dunnr documentation built on Aug. 8, 2022, 12:28 p.m.