Skip to contents

The following plots will be used as examples, to provide customizations features.

library(ggplot2)
p_colour <- 
  ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, color = Species)) + 
  geom_point(size = 4)

p_fill <-
  ggplot(diamonds, aes(x = clarity, fill = color)) + 
  geom_bar(position = position_dodge())

df <- data.frame(
 x = runif(100),
 y = runif(100),
 z1 = rnorm(100),
 z2 = abs(rnorm(100))
)

p_gradient <-
  ggplot(df, aes(x, y)) +
  geom_point(aes(colour = z1), size = 3) +
  theme_bw()

p_fill_gradient <-
  ggplot(faithfuld, aes(waiting, eruptions)) +
  geom_raster(aes(fill = density))

Installation

The moment you load the g6tr.theme package, the fonts we use are copied to your directory.

Please go to the g6tr.theme/fonts/Raleway directory, open up the following fonts and press install:

  • Raleway-Regular.ttf
  • Raleway-Light.ttf
  • Raleway-Bold.ttf

On Windows: Be aware that if you want to manually specify the family above elsewhere, you need to use this:

grDevices::windowsFonts(`Raleway` = grDevices::windowsFont("Raleway"))
grDevices::windowsFonts(`Raleway Light` = grDevices::windowsFont("Raleway Light"))
grDevices::windowsFonts(`Raleway Bold` = grDevices::windowsFont("Raleway Bold"))

Your font names are then:

  • Raleway
  • Raleway Light
  • Raleway Bold

In the case you would like to manually replace fonts in the plot, you could do it like geom_text(font_family = "IBM Plex Sans").

And should use them as such geom_text(font_family = "Raleway")

populace_pal() - palettes

You can use Populace branded palettes provided in theme_populace:

with the usage of populace_pal() function

# populace_pal('core') is a function, populace_pal('core')(7) is a call to export 7 first colors

scales::show_col(populace_pal('core')(10))

scales::show_col(populace_pal('neutrals')(3))

scales::show_col(populace_pal('vary')(13))

# populace_pal('names') let's you see the values and the initial order of the color palette
populace_pal('names')
       core_blue         core_red      core_yellow       core_green 
       "#006DA2"        "#D43F27"        "#FEBC11"        "#98C13D" 
  core_lightblue      core_orange   core_darkgreen    core_darkblue 
       "#00A8B4"        "#EE7622"        "#385528"        "#184269" 
    core_darkred core_lightyellow           grey_1           grey_2 
       "#792015"        "#FEEC53"        "#8F928E"        "#B1B3AF" 
          grey_3 
       "#D5D5D3" 
# populace_pal('core') is a function, populace_pal('core')(4) is a call to return 4 first colors
# rearrange the order of colors returned
populace_pal('core', order = c(3, 2, 1, 7:4))(4)
[1] "#FEBC11" "#D43F27" "#006DA2" "#385528"

those values can be used in manual settings of scales.

p_colour + scale_color_manual(values = populace_pal('core')(3))

p_colour + scale_color_manual(values = populace_pal('core', order = c(3, 2, 1, 4:7))(3))

  p_fill + scale_fill_manual( values = populace_pal()(7)) # core by default

theme_populace() - fonts and layout

This theme automatically loads all fonts if you have installed them. The basic text geom_* are also changed to work with our fonts. Take a regular text geom for example:

ggplot(mtcars,
  aes(wt, mpg, label = rownames(mtcars), colour = factor(cyl))) +
  geom_point() +
  geom_label() + 
  theme_populace()

title = 'Title in Raleway'
subtitle = 'Subtitle in Raleway'
xaxis = 'Raleway'
yaxis = 'Raleway'

However, if for example, you use the ggrepel package and apply the geom_repel, you’ll need to use the following:

library(ggrepel)
update_geom_defaults("text_repel",
                     list(colour = "#8F928E",   
                          family = "Raleway",
                          size = 4))
#OR

ggplot(mtcars,
  aes(wt, mpg, label = rownames(mtcars), colour = factor(cyl))) +
  geom_point() +
  geom_label_repel(family = "Raleway", size = 4) + 
  theme_populace()

White Theme

The default uses major gridlines on the X-axis. This goes well together with the coord_flip() function. However. If you decide to remove the coord_flip(), make sure you add this line:

theme(panel.grid.major.y = element_line(colour = "#B1B3AF"),
      panel.grid.major.x = element_blank())
 ggplot(diamonds, aes(x = clarity, fill = color)) + 
 geom_bar(position = position_dodge()) +
 theme_populace() +
 labs(title = title,
       subtitle = subtitle,
       x = xaxis,
       y = yaxis) +
 coord_flip() 

Finalizing & saving your plot

You can find the created plots in the directory of the package: g6tr.theme/inst/plots

Transparent Background (Default)

myplot <- 
  ggplot(diamonds, aes(x = clarity, fill = color)) +
  geom_bar(position = position_dodge()) +
  theme_populace(transparent = TRUE, base_size = 16) +
  labs(
    title = title,
    subtitle = subtitle,
    x = xaxis,
    y = yaxis
  ) +
  coord_flip()

Simple blank transparent themed plot.

# Invisibly returns a plot as well so you can still use it

finalise_plot(
  plot = myplot,
  filepath = '',
  width_pixels = 600,
  height_pixels = 800,
  brand = 'populace'
)

White Background

 myplot <- 
  ggplot(diamonds, aes(x = clarity, fill = color)) +
  geom_bar(position = position_dodge()) +
  theme_populace() +
  labs(title = title,
       subtitle = subtitle,
       x = xaxis,
       y = yaxis) +
  coord_flip()

Adding a footer with both a source on the left and a logo on the right.

# Invisibly returns a plot as well so you can still use it

finalise_plot(
  plot = myplot,
  add_footer = T,
  filepath = '',
  source = 'Source: Left hand side',
  width_pixels = 600,
  height_pixels = 800,
  brand = 'populace',
  logo = T, #Whether to include the logo or not
  background_color = 'white'
)

Saving the plot without a footer

# Invisibly returns a plot as well so you can still use it

finalise_plot(
  plot = myplot,
  add_footer = F,
  filepath = '',
  width_pixels = 600,
  height_pixels = 800,
  brand = 'populace',
  logo = F, #Should be False if no footer (also done automatically)
  background_color = 'white'
)

Colored Background

Note that this only works when saving the plot. If you want to have the background changed in the plot inline you’ll need to change that in the plot theme itself. See example:

 myplot <- 
  ggplot(diamonds, aes(x = clarity, fill = color)) +
  geom_bar(position = position_dodge()) +
  theme_populace(transparent = TRUE) +
  labs(title = title,
       subtitle = subtitle,
       x = xaxis,
       y = yaxis) +
  coord_flip()

Adding a footer with both a source on the left and a logo on the right. Inline it doesn’t work:

# Invisibly returns a plot as well so you can still use it

finalise_plot(
  plot = myplot,
  add_footer = T,
  filepath = 'colored_with_footer.png',
  source = 'Source: Left hand side',
  width_pixels = 600,
  height_pixels = 800,
  brand = 'populace',
  logo = T, #Whether to include the logo or not
  background_color = '#FEEC53' #Use type = transparent in the theme to get the full background colored
)

But if you read the image it does:

knitr::include_graphics("colored_with_footer.png")

Saving the plot without a footer

# Invisibly returns a plot as well so you can still use it

finalise_plot(
  plot = myplot,
  add_footer = F,
  filepath = '',
  width_pixels = 600,
  height_pixels = 800,
  brand = 'populace',
  logo = F, #Should be False if no footer (also done automatically)
  background_color = 'white'
)