Opinionated, typographic-centric ggplot2 themes and theme components
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
boB Rudis 58fc9b1909
removed purrr dependency
7 years ago
R removed purrr dependency 7 years ago
README_figs Forgot to update vdiffr tests; tweaked theme(s) base font size to 11.5; updated README 7 years ago
README_files/figure-markdown_github spell check example tweak 7 years ago
docs Fixes #7; Added visual diff tests; made `gg_check()` optional; Moved `hunspell` and `stringi` to `Suggests`; Fixed typos. 7 years ago
inst removed purrr dependency 7 years ago
man removed purrr dependency 7 years ago
tests Forgot to update vdiffr tests; tweaked theme(s) base font size to 11.5; updated README 7 years ago
vignettes Fixes #7; Added visual diff tests; made `gg_check()` optional; Moved `hunspell` and `stringi` to `Suggests`; Fixed typos. 7 years ago
.Rbuildignore Fixes #7; Added visual diff tests; made `gg_check()` optional; Moved `hunspell` and `stringi` to `Suggests`; Fixed typos. 7 years ago
.gitignore CRAN Downloads Badge in README 7 years ago
.travis.yml removed purrr dependency 7 years ago
CONDUCT.md initial commit (that also, miraculously, passes CRAN checks) 7 years ago
DESCRIPTION removed purrr dependency 7 years ago
LICENSE some basic tests, LICENSE file and updated travis config 7 years ago
NAMESPACE removed purrr dependency 7 years ago
NEWS.md Forgot to update vdiffr tests; tweaked theme(s) base font size to 11.5; updated README 7 years ago
README.Rmd keybase 7 years ago
README.md Forgot to update vdiffr tests; tweaked theme(s) base font size to 11.5; updated README 7 years ago
cran-comments.md CRAN badge 7 years ago
hrbrthemes.Rproj initial commit (that also, miraculously, passes CRAN checks) 7 years ago

README.md

hrbrthemes : Additional Themes and Theme Components for 'ggplot2'

Project Status: Active - The project has reached a stable, usable state and is being actively developed. codecov Travis-CI Build Status CRAN\_Status\_Badge downloads keybase verified


This is a very focused package that provides typography-centric themes and theme components for ggplot2. It's a an extract/riff of hrbrmisc created by request.

The core theme: theme_ipsum ("ipsum" is Latin for "precise") uses Arial Narrow which should be installed on practically any modern system, so it's "free"-ish. This font is condensed, has solid default kerning pairs and geometric numbers. That's what I consider the "font trifecta" must-have for charts. An additional quality for fonts for charts is that they have a diversity of weights. Arial Narrow (the one on most systems, anyway) does not have said diversity but this quality is not (IMO) a "must have".

The following functions are implemented/objects are exported:

  • theme_ipsum : Arial Narrow-based theme
  • theme_ipsum_rc : Roboto Condensed-based theme
  • gg_check: Spell check ggplot2 plot labels
  • update_geom_font_defaults: Update matching font defaults for text geoms (the default is — unsurprisingly — Arial Narrow)
  • scale_x_comma / scale_y_comma : Comma format for axis text and expand=c(0,0) (you need to set limits)
  • scale_x_percent / scale_y_percent : Percent format for axis text and expand=c(0,0) (you need to set limits)
  • scale_color_ipsum / scale_fill_ipsum / ipsum_pal : A muted discrete color palette with 9 colors
  • font_an: a short global alias for "Arial Narrow"
  • font_rc: a short global alias for "Roboto Condensed"
  • font_rc_light: a short global alias for "Roboto Condensed Light"

Installation

devtools::install_github("hrbrmstr/hrbrthemes")

Usage

library(hrbrthemes)
library(gcookbook)
library(tidyverse)

# current verison
packageVersion("hrbrthemes")
## [1] '0.2.0'

Base theme (Arial Narrow)

ggplot(mtcars, aes(mpg, wt)) +
  geom_point() +
  labs(x="Fuel effiiency (mpg)", y="Weight (tons)",
       title="Seminal ggplot2 scatterplot example",
       subtitle="A plot that is only useful for demonstration purposes",
       caption="Brought to you by the letter 'g'") + 
  theme_ipsum()

Roboto Condensed

ggplot(mtcars, aes(mpg, wt)) +
  geom_point() +
  labs(x="Fuel effiiency (mpg)", y="Weight (tons)",
       title="Seminal ggplot2 scatterplot example",
       subtitle="A plot that is only useful for demonstration purposes",
       caption="Brought to you by the letter 'g'") + 
  theme_ipsum_rc()

Scales (Color/Fill)

ggplot(mtcars, aes(mpg, wt)) +
  geom_point(aes(color=factor(carb))) +
  labs(x="Fuel effiiency (mpg)", y="Weight (tons)",
       title="Seminal ggplot2 scatterplot example",
       subtitle="A plot that is only useful for demonstration purposes",
       caption="Brought to you by the letter 'g'") + 
  scale_color_ipsum() +
  theme_ipsum_rc()

Scales (Axis)

count(mpg, class) %>% 
  mutate(pct=n/sum(n)) %>% 
  ggplot(aes(class, pct)) +
  geom_col() +
  scale_y_percent() +
  labs(x="Fuel effiiency (mpg)", y="Weight (tons)",
       title="Seminal ggplot2 column chart example with percents",
       subtitle="A plot that is only useful for demonstration purposes",
       caption="Brought to you by the letter 'g'") + 
  theme_ipsum(grid="Y")

ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup)) + 
  geom_area() +
  scale_fill_ipsum() +
  scale_x_continuous(expand=c(0,0)) +
  scale_y_comma() +
  labs(title="Age distribution of population in the U.S., 1900-2002",
       subtitle="Example data from the R Graphics Cookbook",
       caption="Source: R Graphics Cookbook") +
  theme_ipsum_rc(grid="XY") +
  theme(axis.text.x=element_text(hjust=c(0, 0.5, 0.5, 0.5, 1))) +
  theme(legend.position="bottom")

update_geom_font_defaults(font_rc_light)

count(mpg, class) %>% 
  mutate(n=n*2000) %>% 
  arrange(n) %>% 
  mutate(class=factor(class, levels=class)) %>% 
  ggplot(aes(class, n)) +
  geom_col() +
  geom_text(aes(label=scales::comma(n)), hjust=0, nudge_y=2000) +
  scale_y_comma(limits=c(0,150000)) +
  coord_flip() +
  labs(x="Fuel effiiency (mpg)", y="Weight (tons)",
       title="Seminal ggplot2 column chart example with commas",
       subtitle="A plot that is only useful for demonstration purposes, esp since you'd never\nreally want direct labels and axis labels",
       caption="Brought to you by the letter 'g'") + 
  theme_ipsum_rc(grid="X")

Spellcheck ggplot2 labels

df <- data.frame(x=c(20, 25, 30), y=c(4, 4, 4), txt=c("One", "Two", "Three"))

ggplot(mtcars, aes(mpg, wt)) +
  geom_point() +
  labs(x="This is some txt", y="This is more text",
       title="Thisy is a titlle",
       subtitle="This is a subtitley",
       caption="This is a captien") +
  theme_ipsum_rc(grid="XY") -> gg

gg_check(gg)
## Possible misspelled words in [title]: (Thisy, titlle)
## Possible misspelled words in [subtitle]: (subtitley)
## Possible misspelled words in [caption]: (captien)

Test Results

library(hrbrthemes)
library(testthat)

date()
## [1] "Thu Mar  2 10:25:50 2017"

test_dir("tests/")
## testthat results ========================================================================================================
## OK: 12 SKIPPED: 0 FAILED: 0
## 
## DONE ===================================================================================================================
## You rock!

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.