View source: R/add-facet-borders.R
add_facet_borders | R Documentation |
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.
add_facet_borders(color = "grey70", colour)
color, colour |
The color of the border. |
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.