Package 'urbnthemes'

Title: Additional theme and utilities for "ggplot2" in the Urban Institute style
Description: Align "ggplot2" output more closely with the Urban Institute Data Visualization style guide <https://urbaninstitute.github.io/r-at-urban/graphics-guide.html>.
Authors: Aaron R. Williams [aut, cre], Kyle Ueyama [aut], Ajjit Narayanan [aut], Ben Chartoff [aut]
Maintainer: Aaron R. Williams <[email protected]>
License: GPL-3
Version: 0.0.2
Built: 2024-11-03 04:05:39 UTC
Source: https://github.com/UrbanInstitute/urbnthemes

Help Index


The Urban Institute ggplot2 theme

Description

Adds tick axes and axes labels

Usage

add_axis(axis = "y")

Arguments

axis

Axis to drop. "x", "y", or "both"


Import and register Lato font

Description

fontawesome_install tests to see if FontAwesome is imported and registered. If FontAwesome, isn't imported and registered, then fontawesome_install imports and registers FontAwesome with library(extrafont).

Usage

fontawesome_install()

Details

Note: FontAwesome must be installed on your computer for fontawesome_install to work.

Test to see if FontAwesome is imported and registered with fontawesome_test().


Test for FontAwesome import and registration

Description

fontawesome_test tests to see if FontAwesome is imported and registered. FontAwesome is used for glyphs with library(waffle) and can be installed from Bob Rudis's GitHub.

Usage

fontawesome_test()

Details

Import and register FontAwesome in R with fontawesome_install().


geom_bar in the Urban Institute style

Description

Submit ?ggplot2::geom_line to see the full documentation for geom_bar()

Usage

geom_bar(mapping = NULL, width = 0.7, ...)

Arguments

mapping

mapping from ggplot2

width

bar width

...

other arguments passed to geom_bar()


geom_col in the Urban Institute style

Description

Submit ?ggplot2::geom_line to see the full documentation for geom_col()

Usage

geom_col(mapping = NULL, width = 0.7, ...)

Arguments

mapping

mapping from ggplot2

width

column width

...

other arguments passed to geom_col()


get_legend

Description

Extract just the legend from a ggplot2 object.

Usage

get_legend(ggplot_object)

Arguments

ggplot_object

a ggplot

Value

a ggplot legend


Import and register Lato font

Description

lato_import() tests to see if Lato is imported and registered. If Lato, isn't imported and registered, then lato_import() imports and registers Lato with library(extrafont).

Usage

lato_import()

Details

Note: Lato must be installed on your computer for lato_import() to work. Lato is the Urban Institute's main font. To install, visit Google fonts and click "Download family". Unzip and open each of the .ttf files and click install.

Test to see if Lato is imported and registered with lato_test().


Import and register Lato font

Description

[Deprecated]

lato_install() was deprecated because its name was ambiguous. Please use lato_import().

Usage

lato_install()

Test for Lato import and registration

Description

lato_test tests to see if Lato is imported and registered. Lato is the Urban Institute's main font and can be installed from Google fonts.

Usage

lato_test()

Details

Import and register Lato in R with lato_install().


The Urban Institute ggplot2 theme

Description

Palette data for the Urban Institute

Usage

palette_urbn

Format

A list.

Details

Data used by the palettes in the uithemes package.


Urban Institute palettes

Description

Vectors with hex-color codes that correspond to the color palettes outlined in the Urban Institute Data Visualization Style Guide. http://urbaninstitute.github.io/graphics-styleguide/

Usage

palette_urbn_main

palette_urbn_diverging

palette_urbn_quintile

palette_urbn_politics

palette_urbn_cyan

palette_urbn_gray

palette_urbn_yellow

palette_urbn_magenta

palette_urbn_green

palette_urbn_spacegray

palette_urbn_red

Format

An object of class character of length 8.

An object of class character of length 8.

An object of class character of length 5.

An object of class character of length 2.

An object of class character of length 8.

An object of class character of length 8.

An object of class character of length 8.

An object of class character of length 8.

An object of class character of length 8.

An object of class character of length 8.

An object of class character of length 8.

Source

Urban Institute Data Visualization Style Guide http://urbaninstitute.github.io/graphics-styleguide/


The Urban Institute ggplot2 theme

Description

Removes axes and axes labels

Usage

remove_axis(axis = "y", flip = FALSE)

Arguments

axis

Axis to drop. "x", "y", or "both"

flip

TRUE/FALSE is coord_flip() is used


remove_legend

Description

Remove just the legend from a ggplot2 object.

Usage

remove_legend(ggplot_object)

Arguments

ggplot_object

a ggplot

Value

a ggplot without a legend


The Urban Institute ggplot2 theme

Description

Removes tick marks from all axes

Usage

remove_ticks(axis = "both")

Arguments

axis

Axis to drop. "x", "y", or "both"


Discrete color scale that aligns with the Urban Institute style

Description

This function can only handle up to 8 categories/colors.

Usage

scale_color_discrete(...)

Arguments

...

other arguments passed to discrete_scale()

Details

If you need more than 8 colors for exploratory purposes, use ggplot2::scale_fill_discrete().


Continuous fill scale that aligns with the Urban Institute style

Description

Continuous fill scale that aligns with the Urban Institute style

Usage

scale_color_gradientn(
  ...,
  colours = c("#CFE8F3", "#A2D4EC", "#73BFE2", "#46ABDB", "#1696D2", "#12719E",
    "#0A4C6A", "#062635"),
  colors = c("#CFE8F3", "#A2D4EC", "#73BFE2", "#46ABDB", "#1696D2", "#12719E",
    "#0A4C6A", "#062635"),
  values = NULL,
  space = "Lab",
  na.value = "grey50",
  guide = "colourbar"
)

Arguments

...

other arguments passed to discrete_scale()

colours

vector of colours

colors

vector of colours

values

if colours should not be evenly positioned along the gradient this vector gives the position (between 0 and 1) for each colour in the colours vector. See rescale for a convience function to map an arbitrary range to between 0 and 1

space

colour space in which to calculate gradient. Must be "Lab" - other values are deprecated.

na.value

default color for NA values

guide

legend representation of scale


Discrete color scale for ordinal factors that aligns with the Urban Institute style

Description

This function can only handle up to 8 categories/colors.

Usage

scale_color_ordinal(...)

Arguments

...

other arguments passed to discrete_scale()

Details

If you need more than 8 colors for exploratory purposes, use ggplot2::scale_color_ordinal().


Discrete color scale that aligns with the Urban Institute style

Description

This function can only handle up to 8 categories/colors.

Usage

scale_colour_discrete(...)

Arguments

...

other arguments passed to discrete_scale()

Details

If you need more than 8 colors for exploratory purposes, use ggplot2::scale_color_discrete().


Continuous fill scale that aligns with the Urban Institute style

Description

Continuous fill scale that aligns with the Urban Institute style

Usage

scale_colour_gradientn(
  ...,
  colours = c("#CFE8F3", "#A2D4EC", "#73BFE2", "#46ABDB", "#1696D2", "#12719E",
    "#0A4C6A", "#062635"),
  colors = c("#CFE8F3", "#A2D4EC", "#73BFE2", "#46ABDB", "#1696D2", "#12719E",
    "#0A4C6A", "#062635"),
  values = NULL,
  space = "Lab",
  na.value = "grey50",
  guide = "colourbar"
)

Arguments

...

other arguments passed to discrete_scale()

colours

vector of colours

colors

vector of colours

values

if colours should not be evenly positioned along the gradient this vector gives the position (between 0 and 1) for each colour in the colours vector. See rescale for a convience function to map an arbitrary range to between 0 and 1

space

colour space in which to calculate gradient. Must be "Lab" - other values are deprecated.

na.value

default color for NA values

guide

legend representation of scale


Discrete color scale for ordinal factors that aligns with the Urban Institute style

Description

This function can only handle up to 8 categories/colors.

Usage

scale_colour_ordinal(...)

Arguments

...

other arguments passed to discrete_scale()

Details

If you need more than 8 colors for exploratory purposes, use ggplot2::scale_colour_ordinal().


Discrete fill scale that aligns with the Urban Institute style

Description

This function can only handle up to 8 categories/colors.

Usage

scale_fill_discrete(...)

Arguments

...

other arguments passed to discrete_scale()

Details

If you need more than 8 colors for exploratory purposes, use ggplot2::scale_fill_discrete().


Continuous fill scale that aligns with the Urban Institute style

Description

Continuous fill scale that aligns with the Urban Institute style

Usage

scale_fill_gradientn(
  ...,
  colours = c("#CFE8F3", "#A2D4EC", "#73BFE2", "#46ABDB", "#1696D2", "#12719E",
    "#0A4C6A", "#062635"),
  colors = c("#CFE8F3", "#A2D4EC", "#73BFE2", "#46ABDB", "#1696D2", "#12719E",
    "#0A4C6A", "#062635"),
  values = NULL,
  space = "Lab",
  na.value = "grey50",
  guide = "colourbar"
)

Arguments

...

other arguments passed to discrete_scale()

colours

vector of colours

colors

vector of colours

values

if colours should not be evenly positioned along the gradient this vector gives the position (between 0 and 1) for each colour in the colours vector. See rescale for a convience function to map an arbitrary range to between 0 and 1

space

colour space in which to calculate gradient. Must be "Lab" - other values are deprecated.

na.value

default color for NA values

guide

legend representation of scale


Discrete fill scale for ordinal factors that aligns with the Urban Institute style

Description

This function can only handle up to 8 categories/colors.

Usage

scale_fill_ordinal(...)

Arguments

...

other arguments passed to discrete_scale()

Details

If you need more than 8 colors for exploratory purposes, use ggplot2::scale_fill_ordinal().


The Urban Institute ggplot2 theme

Description

Adds vertical grid lines to plots for scatter plots. This is useful for scatter plots because urbnthemes only supplies horizontal grid lines.

Usage

scatter_grid()

The Urban Institute ggplot2 theme

Description

set_urbn_defaults provides a ggplot2 theme formatted according to the Urban Institute style guide, with sensible defaults.

Usage

set_urbn_defaults(
  style = "print",
  base_size = 8.5,
  base_family = "Lato",
  base_line_size = 0.5,
  base_rect_size = 0.5,
  scale = "continuous"
)

Arguments

style

The default theme style for the R session. "print" or "map".

base_size

The base font size for the theme. All fonts are relative to this value.

base_family

The base font family for the theme.

base_line_size

The base line size for the theme. All line sizes are relative to this value.

base_rect_size

The base rect size for the theme. All rect sizes are relative to this value.

scale

For theme_urbn_map(). Should the legend theme be continuous or discrete?


A ggplot2 theme formatted in the Urban Institute style

Description

theme_urban provides a ggplot2 theme formatted according to the Urban Institute style guide for maps, with sensible defaults.

Usage

theme_urbn_map(
  scale = "continuous",
  base_size = 8.5,
  base_family = "Lato",
  base_line_size = 0.5,
  base_rect_size = 0.5
)

Arguments

scale

"continuous" creates a vertical legend to the right of the map. "discrete" creates a horizontal legend above the map.

base_family, base_size

base font family and size

base_line_size, base_rect_size

base line and rectangle sizes


A ggplot2 theme formatted in the Urban Institute style

Description

theme_urban provides a ggplot2 theme formatted according to the Urban Institute style guide for web, with sensible defaults.

Usage

theme_urbn_print(
  base_size = 8.5,
  base_family = "Lato",
  base_line_size = 0.5,
  base_rect_size = 0.5
)

Arguments

base_family, base_size

base font family and size

base_line_size, base_rect_size

base line and rectangle sizes


The Urban Institute ggplot2 theme

Description

Resets all the ggplot2 theme to its default settings

Usage

undo_urbn_defaults()

The Urban Institute ggplot2 theme

Description

Color palettes used in the Urban Institute.

Usage

urbn_color_pal(palette = "categorical")

Arguments

palette

Palette name.


Dataset used for creating geofacetted plots in the Urban Institute style.

Description

Dataset used for creating geofacetted plots in the Urban Institute style.

Usage

urbn_geofacet

Format

Data frame with columns

row

Row in geofacet

col

Column in geofacet

code

State abbreviation

name

State name


The Urban Institute ggplot2 theme

Description

Creates a grid object with the Urban Institute logo

Usage

urbn_logo_text()

urbn_note

Description

Add a notes section to the bottom of a plot created with urbn_plot().

Usage

urbn_note(text, size = 8, width = 132, plural = FALSE)

Arguments

text

character string for a note

size

font size for the note

width

a number of characters to allow before a character return

plural

If 'TRUE', will change "Note:" to "Notes:"

Value

a grob formatted for a source in a ggplot


urbn_plot

Description

Combine elements from urbn_title, urbn_subtitle, urbn_y_title, get_legend, remove_legend, urbn_notes, urbn_source, and ggplot2 into one formatted plot.

Usage

urbn_plot(..., heights = 1)

Arguments

...

urbn plot objects or grobs

heights

relative heights of each object in the final plot

Value

one plot made from many grobs


Save ggplot2 plots in standard Urban Institute sizes

Description

This is a function to save standardized images for Urban Institute publications. For more functionality like custom widths and heights, use ggsave() directly.

Usage

urbn_save(
  filename,
  plot = ggplot2::last_plot(),
  size = "medium",
  dpi = 300,
  height = NULL
)

Arguments

filename

File name to create on disk.

plot

Plot to save, defaults to last plot displayed.

size

Size of plot. Must be one of "small" (3.25 x 2 inches), "medium" (6.5 x 4 inches), or "large" (9 x 6.5 inches).

dpi

Plot resolution. Also accepts a string input: "retina" (320), "print" (300), or "screen" (72). Applies only to raster output types.

Examples

## Not run: 
library(tidyverse)
library(urbnthemes)

set_urbn_defaults(style = "print")

cars %>%
  ggplot(aes(speed, dist)) +
  geom_point()

urbn_save("test.png")

## End(Not run)

urbn_source

Description

Add a source section to the bottom of a plot created with urbn_plot().

Usage

urbn_source(text, size = 8, width = 132, plural = FALSE)

Arguments

text

character string for a source

size

font size for the source

width

a number of characters to allow before a character return

plural

If 'TRUE', will change "Source:" to "Sources:"

Value

a grob formatted for a source in a ggplot


urbn_subtitle

Description

Add a subtitle to a plot created with urbn_plot().

Usage

urbn_subtitle(string, size = 9.5)

Arguments

string

character string for a subtitle

size

font size for the subtitle

Value

a grob formatted for a subtitle in a ggplot


urbn_title

Description

Add a title to a plot created with urbn_plot().

Usage

urbn_title(string, size = 12, width = 68)

Arguments

string

character string for a title

size

font size for the title

width

a number of characters to allow before a character return

Value

a grob formatted for a source in a ggplot


urbn_y_title

Description

Add a horizontal y axis title to a plot created with urbn_plot().

Usage

urbn_y_title(string, size = 8.5)

Arguments

string

character string for a y-axis title

size

font size for the y-axis title

Value

a grob formatted for a y-axis title in a ggplot


The Urban Institute ggplot2 theme

Description

view_palette displays the colors and hexadecimal codes for palette_urbn_* vectors.

Usage

view_palette(palette = palette_urbn_main)

Arguments

palette

A palette_urbn_* vector from library(urbnthemes). Options are palette_urbn_diverging, palette_urbn_politics, palette_urbn_quintile, palette_urbn_cyan, palette_urbn_gray, palette_urbn_yellow, palette_urbn_magenta, palette_urbn_green, palette_urbn_spacegray, and palette_urbn_red.

Examples

view_palette()
view_palette(palette_urbn_cyan)