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

https://github.com/teunbrand/elementalist

This repository provides extra theme elements as an extension of ggplot2.
https://github.com/teunbrand/elementalist

ggplot-extension ggplot2 ggplot2-themes visualization

Last synced: about 1 month ago
JSON representation

This repository provides extra theme elements as an extension of ggplot2.

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
ragg_png = function(..., res = 192) {
ragg::agg_supertransparent(..., res = res, units = "in")
}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
dev = "ragg_png",
fig.ext = "png"
)
```

# elementalist

[![Travis build status](https://travis-ci.com/teunbrand/elementalist.svg?branch=master)](https://travis-ci.com/teunbrand/elementalist)
[![Codecov test coverage](https://codecov.io/gh/teunbrand/elementalist/branch/master/graph/badge.svg)](https://codecov.io/gh/teunbrand/elementalist?branch=master)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)

*/ˌɛlɪˈmɛntlɪst/*

## An element of whimsy

elementalist extends the theme element options of [`ggplot2`](http://ggplot2.tidyverse.org). It provides variations on rectangular and line elements that go into ggplot2's `theme()` function, which tweaks the appearance of your plots. The package also has some geoms that are instructed to draw their lines and rectangles according to the theme. This is mostly a pet project that still needs some time to grow.

### Installation

You can install the development version from [GitHub](https://github.com/) with:

``` r
devtools::install_github("teunbrand/elementalist")
```

### Examples

At the moment, the package has three 'styles' to choose from for lines. They are *'wiggle'*, *'multicolour'* and *'glow'*.

#### Wiggle

> It reminded me of the retinal detachment I had last year. Cheers

> -*[Henrik (2020)](https://stackoverflow.com/questions/63061601/how-to-keep-linetype-spacing-constant-despite-line-size/63080260#comment111549473_63080260)*

Here is an example how you can make your elements wiggle!

```{r wiggle}
library(elementalist)

x <- seq(-3, 3, length.out = 20)
df <- data.frame(
x = c(x, x),
y = c(dnorm(x, sd = 1), c(x)/20),
cat = rep(LETTERS[1:2], each = 20)
)

ggplot(df, aes(x, y, colour = cat)) +
geom_line_theme(linewidth = 1) +
coord_cartesian(clip = "off") +
theme(
elementalist.geom_line = element_line_wiggle(6, n = 6),
legend.key = element_rect_wiggle(1, colour = NA),
panel.background = element_rect_wiggle(sides = c("lb"),
colour = "black"),
panel.grid.major = element_line_wiggle(3),
panel.grid.minor = element_line_wiggle(3)
)
```

#### Multicolour

Here is how you can make them colour gradients. It defaults to rainbow colours, but you can set your own.

```{r multicolour}
ggplot(economics, aes(date, unemploy)) +
geom_line_theme() +
theme(
elementalist.geom_line = element_line_multicolour(),
axis.line = element_line_multicolour(),
panel.grid.minor = element_line_multicolour(c("white", "transparent", "white"))
)
```

#### Glow

Glowing lines work well with a dark background. Elementalist has a theme that makes it easy to make a plot quite dark.

```{r glow}
df <- data.frame(
x = rep(c(2, 5, 7, 9, 12), 2),
y = rep(c(1, 2), each = 5),
z = factor(rep(1:5, each = 2)),
w = rep(diff(c(0, 4, 6, 8, 10, 14)), 2)
)

ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +
geom_rect_theme(aes(colour = z), fill = NA) +
scale_colour_manual(
values = c("#00E6FF","#CF77F0", "#8F9FFF",
"#2ABEFF", "#FD006A")
) +
theme_black() +
theme(
panel.grid = element_line_glow(colour = "grey10"),
axis.line = element_line_glow(colour = alpha("#FD006A", 0.5)),
axis.ticks = element_line_glow(colour = alpha("#FD006A", 0.5)),
elementalist.geom_rect = element_rect_glow()
)
```

### Footnotes

This package is still in the experimental phase. Expect some bugs here and there and use at your own risk!

The logo is based on the ['squared circle'](https://en.wikipedia.org/wiki/Alchemical_symbol#/media/File:Squaredcircle.svg) alchemical symbol representing the four elements of matter and the philosopher's stone. With an extra hexagon of course, because this is an R package, after all.