Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/emilhvitfeldt/fontscales

Use Iconographic Fonts in 'ggplot2'
https://github.com/emilhvitfeldt/fontscales

Last synced: about 2 months ago
JSON representation

Use Iconographic Fonts in 'ggplot2'

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# fontscales

[![R-CMD-check](https://github.com/EmilHvitfeldt/fontscales/workflows/R-CMD-check/badge.svg)](https://github.com/EmilHvitfeldt/fontscales/actions)

The goal of fontscales is to is to let you use fancy iconographic fonts with ease in [ggplot2](https://ggplot2.tidyverse.org/).

This package relies heavily on [ragg](https://ragg.r-lib.org/), please see [this article](https://www.tidyverse.org/blog/2021/02/modern-text-features/) for more information.

## Installation

You can install the dev version of fontscales from [Github](http://github.com/) with:

```{r installation, eval=FALSE}
require("devtools")
install_github("EmilHvitfeldt/fontscales")
```

## StateFace

The [StateFace](https://propublica.github.io/stateface/) font by [ProPublica](https://www.propublica.org/) contains the 50 different U.S. states as tiny glyphs and can thus be used in data visualizations.

The data set `usa_arrests` represents a data set where this might be useful where the `state` variable contains the name of the state

```{r}
library(fontscales)
usa_arrests
```

Using `ggplot2` you pass the state name variable to the `label` aesthetic and use `geom_stateface()` to draw the states. (This should function similary to `geom_text()` or `geom_point()`).

```{r}
library(ggplot2)
ggplot(usa_arrests, aes(murder, assault, label = state, color = urban_pop)) +
geom_stateface()
```

And other `ggplot2` functions work as expected

```{r}
library(tidyr)
usa_arrests %>%
pivot_longer(-c(state, urban_pop)) %>%
ggplot(aes(urban_pop, value, label = state)) +
geom_stateface() +
facet_wrap(~name, scales = "free_y")
```