README.md

dfrtheme

R-CMD-check

This is an R package to apply my custom theme on ggplot2 charts.

There are two functions:

Installation

if (!require("devtools")) install_packages("devtools")
library(devtools)
devtools::install_github("dzulfiqarfr/dfrtheme")

Example

library(dplyr)
library(ggplot2)
library(ggtext)
library(gapminder)
library(dfrtheme)

gapminder_latest <- dplyr::filter(gapminder, year == last(year))

ggplot(
  gapminder_latest, 
  aes(x = gdpPercap, y = lifeExp, fill = continent)
) +
  geom_point(
    pch = 21,
    color = "white",
    size = 2.5,
    stroke = 0.25,
    alpha = 0.75
  ) +
  geom_text(
    aes(label = country),
    size = dfr_convert_font_size(),
    check_overlap = TRUE,
    hjust = "inward",
    vjust = "inward"
  ) +
  scale_x_log10() +
  labs(
    title = "Countries with higher income have better public health",
    subtitle = paste0(
      "GDP per capita at 2005 international dollars ",
      "and life expectancy in 2007"
    ),
    x = "GDP per capita<br>(log scale)",
    y = "Life expectancy<br>(years)",
    caption = "Source: Gapminder<br>Chart: Dzulfiqar Fathur Rahman"
  ) +
  dfr_theme()

Read also



dzulfiqarfr/dfrtheme documentation built on Feb. 5, 2022, 1:19 p.m.