knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 6,
  fig.asp = 0.618,
  out.width = '70%',
  warning = FALSE,
  message = FALSE
)

Overview

In order to add a logo you should create your plot, save it, and then use add_logo(). The function takes on six arguments:

Currently, the available built in logos are:

+---------------------------------------------+----------------------------+ | Program/Center | Abbreviation | +:============================================+:===========================+ | Brookings | 'brookings' | +---------------------------------------------+----------------------------+ | Economic Studies | 'es' | +---------------------------------------------+----------------------------+ | Government Studies | 'gs' | +---------------------------------------------+----------------------------+ | Foreign Policy | 'fp' | +---------------------------------------------+----------------------------+ | Metro | 'metro' | +---------------------------------------------+----------------------------+ | Global | 'global' | +---------------------------------------------+----------------------------+ | Bass Initiative | 'bi' | +---------------------------------------------+----------------------------+ | Brown Center | 'bc' | +---------------------------------------------+----------------------------+ | China Center | 'cc' | +---------------------------------------------+----------------------------+ | Center for Children and Families | 'ccf' | +---------------------------------------------+----------------------------+ | Center for East Asia Policy Studies | 'ceaps' | +---------------------------------------------+----------------------------+ | Center for Effective Public Management | 'cepm' | +---------------------------------------------+----------------------------+ | Center for Health Policy | 'chp' | +---------------------------------------------+----------------------------+ | Center for Middle East Policy | 'cmep' | +---------------------------------------------+----------------------------+ | Center for Sustainable Development | 'csd' | +---------------------------------------------+----------------------------+ | Center for Technology Innovation | 'cti' | +---------------------------------------------+----------------------------+ | Center for Universal Education | 'cue' | +---------------------------------------------+----------------------------+ | Center on United States and Europe | 'cuse' | +---------------------------------------------+----------------------------+ | Center on Regulation and Markets | 'crm' | +---------------------------------------------+----------------------------+ | Hutchins Center | 'hc' | +---------------------------------------------+----------------------------+

For more information on how this function works, please read Tom Mock's fantastic blog post on how to add a logo to your plot. ggbrookings::add_logo() builds off of the function described in the article with some minor modifications.

Example

We start by creating a plot and using ggsave() to save it.

ggbrookings::import_inter()
librarian::shelf(ggplot2, ggbrookings, palmerpenguins, magick)
theme_set(theme_brookings())

p1 <-
  ggplot(data = penguins, aes(x = flipper_length_mm)) +
  geom_histogram(aes(fill = species),
                 alpha = 0.5,
                 position = "identity",
                 bins = 30) +
  scale_fill_brookings(palette = "semantic3") +
  labs(x = "Flipper length (mm)",
       y = "Frequency",
       title = "Penguin flipper lengths",
       caption = '**Source:** Palmer Penguins',
       tag = 'FIGURE 1') +
  scale_x_continuous(expand = expansion()) +
  scale_y_continuous(expand = expansion())

ggsave("penguins.png", p1, dpi=300, height=3.7, width=6, units="in")

Finally, to add a logo call:

add_logo('penguins.png', logo_path = 'brookings', 'bottom right', 5)
knitr::include_graphics("../../man/figures/penguins.png", error = FALSE)

The image will show up in your Viewer pane. To save it as a png you can right click on it and select "Save Image As..." or, more reproducibly, assign it to an object and then call magick::image_write() as below:

penguins_plot <- add_logo('penguins.png', logo_path = 'brookings', 'bottom right', 5)

image_write(penguins_plot, "penguins.png")


BrookingsInstitution/ggbrookings documentation built on Jan. 28, 2024, 9:29 p.m.