Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/teunbrand/ggchromatic
Colour and fill scales for 'ggplot2' using colour spaces.
https://github.com/teunbrand/ggchromatic
colors ggplot-extension ggplot2 ggplot2-scales
Last synced: about 1 month ago
JSON representation
Colour and fill scales for 'ggplot2' using colour spaces.
- Host: GitHub
- URL: https://github.com/teunbrand/ggchromatic
- Owner: teunbrand
- License: other
- Created: 2021-01-14T17:23:34.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-24T21:56:59.000Z (over 3 years ago)
- Last Synced: 2024-08-06T03:03:54.732Z (3 months ago)
- Topics: colors, ggplot-extension, ggplot2, ggplot2-scales
- Language: R
- Homepage: https://teunbrand.github.io/ggchromatic/
- Size: 2.25 MB
- Stars: 9
- Watchers: 3
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
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%"
)
```# ggchromatic
*/ʤiː-ʤiːkrəʊˈmætɪk/*
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![R-CMD-check](https://github.com/teunbrand/ggchromatic/workflows/R-CMD-check/badge.svg)](https://github.com/teunbrand/ggchromatic/actions)
[![Codecov test coverage](https://codecov.io/gh/teunbrand/ggchromatic/branch/master/graph/badge.svg)](https://codecov.io/gh/teunbrand/ggchromatic?branch=master)The 'ggchromatic' package provides additional colour and fill scales to use with 'ggplot2' It uses the 'ggplot2' extension system to map a number of variables to different colour spaces with the 'farver' package. The package introduces 'chromatic scales', a term mirroring music terms. In music, chromatic scales cover all 12 notes. In ggchromatic, a chromatic scale can cover all channels in colour space. Admittedly, colour spaces might not be the most intuitive tool for interpreting a data visualisation, but can be useful for visualising less strict data impressions.
## Installation
You can install the development of ggchromatic version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("teunbrand/ggchromatic")
```
## ExampleThese is a basic example of mapping three variables to the RGB colour space. This happens automatically for colours constructed by `rgb_spec()`.
```{r}
library(ggchromatic)ggplot(mtcars, aes(mpg, disp)) +
geom_point(aes(colour = cmy_spec(mpg, drat, wt)))
```The associated scale functions give more options for customisation, like the HSV scale below.
```{r}
df <- data.frame(
x = c(row(volcano)), y = c(col(volcano)), z = c(volcano)
)ggplot(df, aes(x, y, fill = hsv_spec(z, x, y))) +
geom_raster() +
scale_fill_hsv(limits = list(h = c(NA, 170)),
oob = scales::oob_squish,
channel_limits = list(h = c(0, 0.8))) +
coord_equal()
```Perhaps a use-case for chromatic scales is when the interpretation of a variable isn't directly related to a property of the data points. For example, embeddings project data into a new space which might preserve some properties, such as distance between data points, but wherein dimensions of the new space are meaningless on their own. You can use a chromatic scale to map the embedding to colours, which can give a neat 'flavour' to the data points through colour.
```{r}
if (requireNamespace("umap")) {
set.seed(42)# Project the iris dataset into 3D UMAP space
config <- umap::umap.defaults
config$n_components <- 3
umap_3d <- umap::umap(iris[, 1:4], config)$layout
df <- data.frame(
SL = iris$Sepal.Length,
SW = iris$Petal.Width,
x = umap_3d[, 1],
y = umap_3d[, 2],
z = umap_3d[, 3]
)
ggplot(df, aes(SL, SW)) +
geom_point(aes(colour = rgb_spec(x, y, z)))
}
```