pretty_plot: Add a logo and text underneath a plot

View source: R/finalise_plot.R

pretty_plotR Documentation

Add a logo and text underneath a plot

Description

pretty_plot is a wrapper to place a logo at the bottom right and an optional text at the bottom left. It is intended to give a consistent, 'corporate' feel to figures. It adds an extra margin to the plot at the bottom where the logos and text are placed.

Usage

pretty_plot(
  plot,
  source_name = "",
  logo_path,
  text_size = 16,
  theme_apply = TRUE,
  facet_apply = FALSE
)

Arguments

plot

A ggplot to be amended.

source_name

A character string of text to be added bottom left.

logo_path

Filepath to png or jpg file of logo to be added bottom right.

text_size

Font size for the text. Default is 16

theme_apply

Logical. If TRUE applies the HSRC theme to the plot.

facet_apply

Logical. If TRUE applies colour and text size to a facet plot.

Value

A plot with text (left) and logo (right)

Examples

library(ggplot2)
pl_1 <- ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point()
pl_1_no_legend <- ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point(show.legend = FALSE)

pl_1
pl_1_no_legend

pp_pl_1 <- pretty_plot(pl_1, source = "Text 14 point",
logo_path = system.file("extdata", "SNAP3_2019.jpg", package = "testpackage"),
text_size = 14, theme_apply = FALSE)

pp_pl_1

pp_pl_1_no_legend <- pretty_plot(pl_1, source = "Text 16 point, HSRC theme",
logo_path = system.file("extdata", "SNAP3_2019.jpg", package = "testpackage"),
text_size = 16, theme_apply = TRUE)

pp_pl_1_no_legend

pl_2 <- ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_wrap(~class, ncol = 3)

pp_pl_2 <- pretty_plot(pl_2, source_name = "Facet wrap",logo_path = system.file("extdata", "SNAP3_2019.jpg", package = "testpackage"),
text_size = 16, theme_apply = TRUE,
facet_apply = TRUE)

pp_pl_2

IainMoppett/testpackage documentation built on Feb. 4, 2023, 11 p.m.