theme_laviz: A theme for my package

View source: R/theme_laviz.R

theme_lavizR Documentation

A theme for my package

Description

Credit here is owed to the package hrbrthemes by Bob Rudis. I took his code and made tweaks based on my preferences and the changes I tend to make to his themes.

Usage

theme_laviz(
  base_family = "Arial",
  base_size = 11.5,
  base_col = "#323232",
  plot_title_family = base_family,
  plot_title_size = 18,
  plot_title_face = "bold",
  plot_title_margin = 10,
  subtitle_family = base_family,
  subtitle_size = base_size,
  subtitle_face = "plain",
  subtitle_margin = 15,
  strip_text_family = base_family,
  strip_text_size = base_size,
  strip_text_face = "plain",
  caption_family = base_family,
  caption_size = 9,
  caption_face = "italic",
  caption_margin = 10,
  axis_text_family = base_family,
  axis_text_size = base_size,
  axis_title_family = base_family,
  axis_title_size = base_size,
  axis_title_face = "plain",
  axis_title_just = "rt",
  plot_margin = margin(t = 5, l = 5, b = 5, r = 20),
  grid_col = "#D3D3D3",
  grid = TRUE,
  axis_col = base_col,
  axis = FALSE,
  ticks = FALSE,
  border = FALSE
)

Arguments

base_family, base_size

base font family and size

base_col, axis_col

base & axis colors; both default to "#323232", a dark gray. I also like to use "#000000" or "black"

plot_title_family, plot_title_face, plot_title_size, plot_title_margin

plot title family, face, size and margin

subtitle_family, subtitle_face, subtitle_size

plot subtitle family, face and size

subtitle_margin

plot subtitle margin bottom (single numeric value)

strip_text_family, strip_text_face, strip_text_size

facet label font family, face and size

caption_family, caption_face, caption_size, caption_margin

plot caption family, face, size and margin

axis_text_family, axis_text_size

axis text font family and size

axis_title_family, axis_title_face, axis_title_size

axis title font family, face and size

axis_title_just

axis title font justification, one of ⁠[blmcrt]⁠

plot_margin

plot margin (specify with ggplot2::margin())

grid_col

grid colors; defaults to "#D3D3D3"

grid

panel grid (TRUE, FALSE, or a combination of X, x, Y, y)

axis

add x or y axes? TRUE, FALSE, "xy"

ticks

ticks if TRUE add ticks

border

If TRUE adds border around plot area

Examples

## Not run: 
library(ggplot2)
library(dplyr)
library(palmerpenguins)

laviz::view_palette(c("#323232", "#000000", "#D3D3D3", "black"))

# Scatterplot
ggplot(data = penguins,
       aes(x = bill_length_mm,
           y = body_mass_g)) +
  geom_point(aes(colour = species)) +
  labs(x = "Bill length (mm)",
       y = "Body mass (g)",
       title = "ggplot2 scatterplot example",
       subtitle = "A plot that is only useful for demonstration purposes",
       caption = "Data comes from the palmerpenguins package.") +
  theme_laviz(axis = TRUE,
              ticks = TRUE)


# Bar chart example
count(penguins, species) %>%
  ggplot(data = .,
         aes(x = species,
             y = n)) +
  geom_col(width = 0.5) +
  geom_text(aes(label = n),
            nudge_y = 3.5) +
  labs(x = "Species",
       y = NULL,
       title = "ggplot2 bar chart example",
       subtitle = "Number of penguins by species",
       caption = "Data comes from the palmerpenguins package.") +
  theme_laviz(grid = "Y",
              axis = FALSE,
              ticks = FALSE) +
  theme(axis.text.y = element_blank())

# Another scatterplot
ggplot(data = penguins,
       aes(x = flipper_length_mm,
           y = body_mass_g)) +
  geom_point(aes(colour = species,
                 shape = species),
             size = 2) +
  theme_laviz()  +
  scale_color_manual(values = c("darkorange", "darkorchid", "cyan4")) +
  labs(x = "Flipper length (mm)",
       y = "Body mass (g)",
       title = "Penguin flipper length versus body mass",
       subtitle = "There is a positive correlation between flipper length and body mass.",
       caption = "Data comes from the palmerpenguins package.",
       colour = "Species",
       shape = "Species")


## End(Not run)

emilelatour/laviz documentation built on Oct. 15, 2023, 1:41 p.m.