Giter Site home page Giter Site logo

mattschaelling / hrbrthemes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hrbrmstr/hrbrthemes

0.0 1.0 0.0 8.78 MB

:lock_with_ink_pen: Opinionated, typographic-centric ggplot2 themes and theme components

Home Page: https://hrbrmstr.github.io/hrbrthemes/

License: Other

R 93.81% HTML 3.53% CSS 2.66%

hrbrthemes's Introduction

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 DOI

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:

Themes:

  • theme_ft_rc: A precise & pristine ggplot2 theme with opinionated defaults and an emphasis on typoghraphy
  • theme_ipsum: A precise & pristine ggplot2 theme with opinionated defaults and an emphasis on typography
  • theme_ipsum_ps: A precise & pristine ggplot2 theme with opinionated defaults and an emphasis on typoghraphy
  • theme_ipsum_rc: A precise & pristine ggplot2 theme with opinionated defaults and an emphasis on typoghraphy
  • theme_ipsum_tw: A precise & pristine ggplot2 theme with opinionated defaults and an emphasis on typoghraphy
  • theme_modern_rc: A precise & pristine ggplot2 theme with opinionated defaults and an emphasis on typoghraphy

Scales (that align with various themes):

  • scale_color_ft: Discrete color & fill scales based on the FT palette
  • scale_color_ipsum: Discrete color & fill scales based on the ipsum palette
  • scale_colour_ft: Discrete color & fill scales based on the FT palette
  • scale_colour_ipsum: Discrete color & fill scales based on the ipsum palette
  • scale_fill_ft: Discrete color & fill scales based on the FT palette
  • scale_fill_ipsum: Discrete color & fill scales based on the ipsum palette
  • scale_x_comma: X & Y scales with opinionated pre-sets for percent & comma label formats
  • scale_x_percent: X & Y scales with opinionated pre-sets for percent & comma label formats
  • scale_y_comma: X & Y scales with opinionated pre-sets for percent & comma label formats
  • scale_y_percent: X & Y scales with opinionated pre-sets for percent & comma label formats

Palettes/Named Colors:

  • ipsum_pal: A muted, qualitative color palette
  • ft_cols: FT color palette
  • ft_pal: A bright qualitative color palette
  • ft_text_col: FT color palette

Fonts:

  • font_an: Arial Narrow font name R variable aliases
  • font_ps: PlexSans font name R variable aliases
  • font_ps_light: PlexSans font name R variable aliases
  • font_rc: Roboto Condensed font name R variable aliases
  • font_rc_light: Roboto Condensed font name R variable aliases
  • font_tw: Titillium Web font name R variable aliases
  • font_tw_bold: Titillium Web font name R variable aliases
  • font_tw_light: Titillium Web font name R variable aliases

R Markdown:

  • ipsum: ipsum R markdown template
  • ipsum_pdf: ipsum R markdown template for PDF output

Utilities:

  • flush_ticks: Makes axis text labels flush on the ends
  • ft_geom_defaults: Change geom defaults from black to custom lights for the FT theme
  • gg_check: Spell check ggplot2 plot labels
  • import_plex_sans: Import IBM Plex Sans font for use in charts
  • import_roboto_condensed: Import Roboto Condensed font for use in charts
  • import_titillium_web: Import Titillium Web font for use in charts
  • modern_geom_defaults: Change geom defaults from black to white for the modern theme
  • update_geom_font_defaults: Update matching font defaults for text geoms

Installation

devtools::install_github("hrbrmstr/hrbrthemes")

Usage

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

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

Base theme (Arial Narrow)

ggplot(mtcars, aes(mpg, wt)) +
  geom_point() +
  labs(x="Fuel efficiency (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 efficiency (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()

New FT Theme!

ggplot(mtcars, aes(mpg, wt)) +
  geom_point(color = ft_cols$yellow) +
  labs(x="Fuel efficiency (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_ft_rc()

IBM Plex Sans

ggplot(mpg, aes(displ, hwy)) +
  geom_jitter(aes(color=class, fill=class), size=3, shape=21, alpha=1/2) +
  scale_x_continuous(expand=c(0,0), limits=c(1, 8), breaks=1:8) +
  scale_y_continuous(expand=c(0,0), limits=c(10, 50)) +
  scale_color_ipsum() +
  scale_fill_ipsum() +
  facet_wrap(~class, scales="free") +
  labs(
    title="IBM Plex Sans Test",
    subtitle="This is a subtitle to see the how it looks in IBM Plex Sans",
    caption="Source: hrbrthemes & IBM"
  ) +
  theme_ipsum_ps(grid="XY", axis="xy") +
  theme(legend.position="none") -> gg

flush_ticks(gg)
## theme(axis.text.x=element_text(hjust=c(0, rep(0.5, 6), 1))) +
## theme(axis.text.y=element_text(vjust=c(0, rep(0.5, 3), 1)))

Titillium Web

ggplot(mpg, aes(displ, hwy)) +
  geom_jitter(aes(color=class, fill=class), size=3, shape=21, alpha=1/2) +
  scale_x_continuous(expand=c(0,0), limits=c(1, 8), breaks=1:8) +
  scale_y_continuous(expand=c(0,0), limits=c(10, 50)) +
  scale_color_ipsum() +
  scale_fill_ipsum() +
  facet_wrap(~class, scales="free") +
  labs(
    title="Titillium Web",
    subtitle="This is a subtitle to see the how it looks in Titillium Web",
    caption="Source: hrbrthemes & Google"
  ) +
  theme_ipsum_tw(grid="XY", axis="xy") +
  theme(legend.position="none") -> gg

flush_ticks(gg)
## theme(axis.text.x=element_text(hjust=c(0, rep(0.5, 6), 1))) +
## theme(axis.text.y=element_text(vjust=c(0, rep(0.5, 3), 1)))

Scales (Color/Fill)

ggplot(mtcars, aes(mpg, wt)) +
  geom_point(aes(color=factor(carb))) +
  labs(x="Fuel efficiency (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 efficiency (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 efficiency (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)

hrbrthemes Metrics

Lang # Files (%) LoC (%) Blank lines (%) # Lines (%)
R 20 0.91 1083 0.9 212 0.68 582 0.78
Rmd 2 0.09 124 0.1 99 0.32 162 0.22

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.

hrbrthemes's People

Contributors

hrbrmstr avatar jofam avatar benmarwick avatar bhaskarvk avatar barnettjacob avatar jemus42 avatar phillyo avatar xvrdm avatar karldw avatar mpancia avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.