Skip to content
Urban Institute's ggplot2 theme and tools. NOTE: this is under active development
Branch: master
Clone or download
awunderground Merge pull request #52 from UI-Research/aaron_draft
Changes to pkgdown, README, vignettes
Latest commit cc0c4bd May 16, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R Fix typo in zzz.R that caused differences between operating systems. Jan 28, 2019
data-raw Close #20. Add urbn_geofacet. Dec 7, 2018
data Close #20. Add urbn_geofacet. Dec 7, 2018
docs Add pkgdown, add COMM examples to the README, delete the graphics gui… May 15, 2019
man Add pkgdown, add COMM examples to the README, delete the graphics gui… May 15, 2019
vignettes
.Rbuildignore Resolve devtools::check() errors and notes. Dec 10, 2018
.gitignore
.travis.yml add travis ci, add package references to fix majority of R CMD CHECK … May 31, 2018
CODE_OF_CONDUCT.md
DESCRIPTION Add pkgdown, add COMM examples to the README, delete the graphics gui… May 15, 2019
NAMESPACE Entirely abandon library(conflicted). Close #49. Jan 26, 2019
NEWS.md Permanently abandon library(conflicted). Close #49. Jan 26, 2019
README.Rmd
README.md Add vignette and add devtools::install_github(UI-Research/urbnthemes,… May 15, 2019
hexsticker.R Close #21. Added a rough hexsticker. Dec 7, 2018
urbnthemes.Rproj Update to reflect the package name 'urbnthemes' May 9, 2018

README.md

urbnthemes

Travis-CI Build Status

Overview

urbnthemes is a set of tools for creating Urban Institute-themed plots and maps in R. The package extends ggplot2 with print and map themes as well as tools that make plotting easier at the Urban Institute. urbnthemes replaces the urban_R_theme.

A comprehensive set of examples is available at the Urban Institute R Users Group website.

Installation

install.packages("devtools")
devtools::install_github("UI-Research/urbnthemes", build_vignettes = TRUE)

Fonts

The Urban Institute uses Lato font for publications. After installing urbnthemes, submit urbnthemes::lato_test() to see if Lato is imported and registered.

If Lato isn’t imported and registered, install Lato and then submit urbnthemes::lato_install(). If you are on a Windows, you may need to install ghostscript and then submit Sys.setenv(R_GSCMD = "link to the ghostscript .exe") before running urbnthemes::lato_install().

Waffle charts with glyphs require fontawesome. fontawesome_test() and fontawesome_install() are the fontawesome versions of the above functions. Be sure to install fontawesome from here.

Usage

Always load library(urbnthemes) after library(ggplot2) or library(tidyverse).

library(tidyverse)
library(urbnthemes)

set_urbn_defaults(style = "print")

ggplot(data = mtcars, mapping = aes(factor(cyl))) +
  geom_bar() + 
  scale_y_continuous(expand = expand_scale(mult = c(0, 0.1))) +
  labs(x = "Number of Cylinders",
       y = "Count") +
  remove_ticks()

ggplot(data = mtcars, mapping = aes(x = wt, y = mpg)) +
  geom_point() +
  scale_x_continuous(expand = expand_scale(mult = c(0.002, 0)), 
                     limits = c(0, 6),
                     breaks = 0:6) +
  scale_y_continuous(expand = expand_scale(mult = c(0, 0.002)), 
                     limits = c(0, 40),
                     breaks = 0:8 * 5) +
  labs(x = "Weight (thousands of pounds)",
       y = "City MPG") +
  scatter_grid()

mtcars %>%
  mutate(cyl = paste(cyl, "cylinders")) %>%
  ggplot(aes(x = wt, y = mpg, color = cyl)) +
  geom_point() +
  scale_x_continuous(expand = expand_scale(mult = c(0.002, 0)), 
                     limits = c(0, 6),
                     breaks = 0:6) +
  scale_y_continuous(expand = expand_scale(mult = c(0, 0.002)), 
                     limits = c(0, 40),
                     breaks = 0:8 * 5) +
  labs(x = "Weight (thousands of pounds)",
       y = "City MPG") +
  scatter_grid()

library(gapminder)

gapminder %>%
  filter(country %in% c("Australia", "Canada", "New Zealand")) %>%
  mutate(country = factor(country, levels = c("Canada", "Australia", "New Zealand"))) %>%
  ggplot(aes(year, gdpPercap, color = country)) +
  geom_line() +
  scale_x_continuous(expand = expand_scale(mult = c(0.002, 0)), 
                     breaks = c(1952 + 0:12 * 5), 
                     limits = c(1952, 2007)) +
  scale_y_continuous(expand = expand_scale(mult = c(0, 0.002)), 
                     breaks = 0:8 * 5000,
                     labels = scales::dollar, 
                     limits = c(0, 40000)) +
  labs(x = "Year",
       y = "Per capita GDP (US dollars)")

txhousing %>%
  filter(city %in% c("Austin","Houston","Dallas","San Antonio","Fort Worth")) %>%
  group_by(city, year) %>%
  summarize(sales = sum(sales)) %>%
  ggplot(aes(x = year, y = sales, fill = city)) +
  geom_area(position = "stack") +
  scale_x_continuous(expand = expand_scale(mult = c(0, 0)),
                     limits = c(2000, 2015),
                     breaks = 2000 + 0:15) +  
  scale_y_continuous(expand = expand_scale(mult = c(0, 0.2)), 
                     labels = scales::comma) +
  labs(x = "Year",
       y = "Home sales")

Branding

library(ggplot2)
library(urbnthemes)
library(grid)
library(gridExtra)
#> 
#> Attaching package: 'gridExtra'

#> The following object is masked from 'package:dplyr':
#> 
#>     combine
set_urbn_defaults()

plot <- ggplot(data = mtcars, mapping = aes(factor(cyl))) +
  geom_bar() + 
  scale_y_continuous(expand = expand_scale(mult = c(0, 0.1))) +
  labs(x = "Number of Cylinders",
       y = "Count") +
  remove_ticks()

grid.arrange(plot, urbn_logo_text(), ncol = 1, heights = c(30, 1))

Core themes:

  • set_urbn_defaults()
  • theme_urbn_print()
  • theme_urbn_map()

Formatting functions:

  • urbn_logo_text()
  • remove_ticks()
  • remove_axis()
  • scatter_grid()
  • add_axis()
  • urbn_geofacet

Utility functions:

  • lato_test()
  • lato_install()
  • fontawesome_test()
  • fontawesome_install()
  • view_palette()

In development:

  • undo_urbn_defaults()
  • save_urbn_print()

Getting help

Contact Aaron Williams or Kyle Ueyama with feedback or questions.

Code of conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

You can’t perform that action at this time.