knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(architekter)

Create a theme function in correspondance with the Figma maquette

library(ggplot2)

my_awesome_theme <- get_figma_file_content(file_key = "wRqIvMmymzSPuj0sEhnORb",
                                  acess_token = Sys.getenv("FIGMA_TOKEN")) %>%
  extract_ggplot_theme() %>% 
  create_theme_fun()

# Toy plot 1
#' \dontrun{
ggplot(data = iris) + 
  aes(x = Sepal.Width, fill = Species) + 
  geom_density() + 
  labs(title = "Sepal width of several species of iris",
       subtitle = "This plot respects the graphic design system defined in Figma",
       x = "Sepal width",
       y = "Density", 
       color = "Iris species") +
  my_awesome_theme()
#' }

# Toy plot 2
#' \dontrun{
ggplot(data = iris) + 
  aes(x = Sepal.Width, fill = Species) + 
  geom_density() + 
  labs(title = "Sepal width of several species of iris",
       subtitle = "This plot respects the graphic design system defined in Figma",
       x = "Sepal width",
       y = "Density", 
       color = "Iris species") +
  my_awesome_theme(legend.position = "bottom")
#' }

# Toy plot 3
#' \dontrun{
ggplot(data = iris) + 
  aes(x = Sepal.Length, y = Sepal.Width, color = Species) + 
  geom_point() + 
  labs(title = "Relationship between sepal length and sepal width of several species of iris",
       subtitle = "This plot respects the graphic design system defined in Figma",
       x = "Sepal length",
       y = "Sepal width", 
       color = "Iris species") +
  my_awesome_theme()
#' }

# Toy plot 4
#' \dontrun{
ggplot(data = iris) + 
  aes(x = Sepal.Length, y = Sepal.Width) + 
  geom_point() + 
  labs(title = "Relationship between sepal length and sepal width of several species of iris",
       subtitle = "This plot respects the graphic design system defined in Figma",
       x = "Sepal length",
       y = "Sepal width") +
  facet_grid(cols = vars(Species)) +
  my_awesome_theme()
#' }

Details of the functions

Create a theme function by using the {ggplot2} elements extracted from the Figma file

data(toy_raw_file_content)

library(ggplot2)

my_theme <- toy_raw_file_content %>% 
  extract_ggplot_theme() %>% 
  create_theme_fun()

#' \dontrun{
ggplot(data = iris) + 
  aes(x = Sepal.Width, fill = Species) + 
  geom_density() + 
  labs(title = "Sepal width of several species of iris",
       subtitle = "This plot respects the graphic design system defined in Figma",
       x = "Sepal width",
       y = "Density", 
       color = "Species") +
  my_theme()
#' }


ThinkR-open/swatch documentation built on April 7, 2022, 6:08 p.m.