How to create standard visualizations across SI team with USAID’s alternate fonts, Sans Source Pro.

This font is not only not native to R, nor is it a standard to Windows.

glitr

glitr is SI graphics package to adorn your plots with ggplot

Installation

glitr is not on CRAN, so you will have to install it directly from Github using devtools.

Follow the installation guide from the github repo

Make sure install Sans Source Pro font as well

Use cases

  • Load required R Packages
library(tidyverse)
library(glitr)
  • Make sure iris sample data is loaded
iris %>%
  glimpse()
iris %>% head()
  • Create a scatter plot with with default ggplot options
iris %>%
  ggplot(aes(Sepal.Length, y = Sepal.Width, colour = Species)) +
  geom_point() +
  labs(x="Length", y="Width",
      title = "IRIS Flowers Study",
      subtitle = "Sepal Dimensions",
      caption = "source: Edgar Anderson's Iris Data")

ggsave("assets/img/tutorials/iris_scatter_plot_default.png")

ggplot default theme

  • Create a scatter plot with with ggplot minimal theme
iris %>%
  ggplot(aes(Sepal.Length, y = Sepal.Width, colour = Species)) +
  geom_point() +
  labs(x="Length", y="Width",
      title = "IRIS Flowers Study",
      subtitle = "Sepal Dimensions",
      caption = "source: Edgar Anderson's Iris Data") +
  theme_minimal()

ggsave("assets/img/tutorials/iris_scatter_plot_minimal.png")

ggplot minimal theme

  • Create a scatter plot with with SI Strandard Styles

si_style() function extends ggplot minimal theme along with a re-adjustement of the plot title, subtitle and capture.

iris %>%
  ggplot(aes(Sepal.Length, y = Sepal.Width, colour = Species)) +
  geom_point() +
  labs(x="Length", y="Width",
      title = "IRIS Flowers Study",
      subtitle = "Sepal Dimensions",
      caption = "source: Edgar Anderson's Iris Data") +
  si_style()

ggsave("assets/img/tutorials/iris_scatter_plot_si_style.png")

ggplot SI Style

si_style_xgrid displays only the x axes

iris %>%
  ggplot(aes(Sepal.Length, y = Sepal.Width, colour = Species)) +
  geom_point() +
  labs(x="Length", y="Width",
      title = "IRIS Flowers Study",
      subtitle = "Sepal Dimensions",
      caption = "source: Edgar Anderson's Iris Data") +
  si_style_xgrid()

ggsave("assets/img/tutorials/iris_scatter_plot_si_style_xgrid.png")

ggplot SI Style xgrid

si_style_ygrid displays only the y axes

iris %>%
  ggplot(aes(Sepal.Length, y = Sepal.Width, colour = Species)) +
  geom_point() +
  labs(x="Length", y="Width",
      title = "IRIS Flowers Study",
      subtitle = "Sepal Dimensions",
      caption = "source: Edgar Anderson's Iris Data") +
  si_style_ygrid()

ggsave("assets/img/tutorials/iris_scatter_plot_si_style_ygrid.png")

ggplot SI Style ygrid

si_style_xline displays only the x line

iris %>%
  ggplot(aes(Sepal.Length, y = Sepal.Width, colour = Species)) +
  geom_point() +
  labs(x="Length", y="Width",
      title = "IRIS Flowers Study",
      subtitle = "Sepal Dimensions",
      caption = "source: Edgar Anderson's Iris Data") +
  si_style_xline()

ggsave("assets/img/tutorials/iris_scatter_plot_si_style_xline.png")

ggplot SI Style xline

si_style_yline displays only the y line

iris %>%
  ggplot(aes(Sepal.Length, y = Sepal.Width, colour = Species)) +
  geom_point() +
  labs(x="Length", y="Width",
      title = "IRIS Flowers Study",
      subtitle = "Sepal Dimensions",
      caption = "source: Edgar Anderson's Iris Data") +
  si_style_yline()

ggsave("assets/img/tutorials/iris_scatter_plot_si_style_yline.png")

ggplot SI Style yline

si_style_xyline displays only the x and y lines

iris %>%
  ggplot(aes(Sepal.Length, y = Sepal.Width, colour = Species)) +
  geom_point() +
  labs(x="Length", y="Width",
      title = "IRIS Flowers Study",
      subtitle = "Sepal Dimensions",
      caption = "source: Edgar Anderson's Iris Data") +
  si_style_xyline()

ggsave("assets/img/tutorials/iris_scatter_plot_si_style_xyline.png")

ggplot SI Style xyline

si_style_nolines displays only the no lines

iris %>%
  ggplot(aes(Sepal.Length, y = Sepal.Width, colour = Species)) +
  geom_point() +
  labs(x="Length", y="Width",
      title = "IRIS Flowers Study",
      subtitle = "Sepal Dimensions",
      caption = "source: Edgar Anderson's Iris Data") +
  si_style_nolines()

ggsave("assets/img/tutorials/iris_scatter_plot_si_style_nolines.png")

ggplot SI Style no lines

Note: These SI Styles are still under construction and all feedback / comments are welcome.