Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mtennekes/cols4all
Colors for all (R package)
https://github.com/mtennekes/cols4all
Last synced: about 2 months ago
JSON representation
Colors for all (R package)
- Host: GitHub
- URL: https://github.com/mtennekes/cols4all
- Owner: mtennekes
- Created: 2022-02-10T12:12:59.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-26T11:44:06.000Z (5 months ago)
- Last Synced: 2024-04-26T12:41:03.827Z (5 months ago)
- Language: R
- Homepage: https://mtennekes.github.io/cols4all/
- Size: 13.8 MB
- Stars: 291
- Watchers: 6
- Forks: 15
- Open Issues: 3
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
Awesome Lists containing this project
- awesome-PhD - COLS4ALL
README
---
output: github_document
editor_options:
chunk_output_type: console
---```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
hook_output <- knitr::knit_hooks$get("output")
knitr::knit_hooks$set(output = function(x, options) {
lines <- options$output.lines
if (is.null(lines)) {
return(hook_output(x, options)) # pass to default hook
}
x <- unlist(strsplit(x, "\n"))
more <- "..."
if (length(lines)==1) { # first n lines
if (length(x) > lines) {
# truncate the output, but add ....
x <- c(head(x, lines), more)
}
} else {
x <- c(more, x[lines], more)
}
# paste these lines together
x <- paste(c(x, ""), collapse = "\n")
hook_output(x, options)
})
```[![CRAN](https://www.r-pkg.org/badges/version/cols4all)](https://cran.r-project.org/package=cols4all)
[![cran checks](https://cranchecks.info/badges/worst/cols4all)](https://cran.r-project.org/web/checks/check_results_cols4all.html)
[![Downloads](https://cranlogs.r-pkg.org/badges/cols4all?color=brightgreen)](https://www.r-pkg.org/pkg/cols4all)**cols4all** is an R package for selecting color palettes. "Color for all" refers to our mission that colors should be usable for not just people with normal color vision, but also for people with color vision deficiency. Currently, this package contains palettes from several popular and lesser known color palette series. Own palettes series can be added as well.
Color palettes are well organized and made consistent with each other. Moreover, they are scored on several aspects: color-blind-friendliness, the presence of intense colors (which should be avoided), the overall aesthetic harmony, and how many different hues are used. Finally, for each color palette a color for missing values is assigned, which is especially important for spatial data visualization. Currently we support several types: *categorical* (qualitative) palettes, *sequential* palettes, *diverging* palettes, and *bivariate* palettes (divided into four subtypes).
## Installation
**cols4all** is available on CRAN:
```{r, eval=FALSE}
install.packages("cols4all", dependencies = TRUE)
```The development version can be installed as follows:
```{r, eval=FALSE}
install.packages("remotes")
remotes::install_github("mtennekes/cols4all", dependencies = TRUE)
``````{r, echo=FALSE, message=FALSE}
devtools::load_all(".")
```## Getting started
Load the package:
```{r, eval=FALSE}
library(cols4all)
```The main tool is a dashboard, which is started with:
```{r, eval=FALSE}
c4a_gui()
```[](vignettes/dash-3.png)
What types and series are available?
```{r}
c4a_types()c4a_series()
```How many palettes per type x series?
```{r}
c4a_overview()
```What palettes are available, e.g diverging from the hcl series?
```{r}
# Diverging palettes from the 'hcl' series
c4a_palettes(type = "div", series = "hcl")
```Give me the colors!
```{r}
# select purple green palette from the hcl series:
c4a("hcl.purple_green", 11)# get the associated color for missing values
c4a_na("hcl.purple_green")
```Plot these colors:
```{r, fig.height = 2}
c4a_plot("hcl.purple_green", 11, include.na = TRUE)
```## Using cols4all palettes in ggplot2
```{r}
library(ggplot2)
data("diamonds")
diam_exp = diamonds[diamonds$price >= 15000, ]# discrete categorical scale
ggplot(diam_exp, aes(x = carat, y = price, color = color)) +
geom_point(size = 2) +
scale_color_discrete_c4a_cat("carto.safe") +
theme_light()# continuous diverging scale
ggplot(diam_exp, aes(x = carat, y = depth, color = price)) +
geom_point(size = 2) +
scale_color_continuous_c4a_div("wes.zissou1", mid = mean(diam_exp$price)) +
theme_light()
```## Overview of functions
Main functions:
* `c4a_gui` Dashboard for analyzing the palettes
* `c4a` Get the colors from a palette (`c4a_na` for the associated color for missing values)
* `c4a_plot` Plot a color palettePalette names and properties:
* `c4a_palettes` Get available palette names
* `c4a_series` Get available series names
* `c4a_types` Get implemented types
* `c4a_overview` Get an overview of palettes per series x type.
* `c4a_citation` Show how to cite palettes (with bibtex code).
* `c4a_info` Get information from a palette, such as type and maximum number
of colors
* `.P` Environment via which palette names can be browsed with
auto-completion (using `$`)Importing and exporting palettes:
* `c4a_data` Build color palette data
* `c4a_load` Load color palette data
* `c4a_sysdata_import` Import system data
* `c4a_sysdata_export` Export system dataEdit color palette data
* `c4a_duplicate` Duplicates a color palette
* `c4a_modify` Modifies palette colorsggplot2
* `scale___c4a_` e.g. `scale_color_continuous_c4a_div` Add scale to ggplot2.
## Related R packages
The foundation of this package is another R package: [**colorspace**](https://colorspace.r-forge.r-project.org/). We use this package to analyse colors. For this purpose and specifically for color blind friendliness checks, we also use [**colorblindcheck**](https://github.com/Nowosad/colorblindcheck).
There are a few other pacakges with a large collection of color palettes, in particular [**pals**](https://kwstat.github.io/pals/) and [**paletteer**](https://github.com/EmilHvitfeldt/paletteer). There are a few features that distinguishes **cols4all** from those packages:
* Color palettes are characterized and analysed. Properties such as color blindness, fairness (whether colors stand out about equally), and contrast are determined for each palette.
* Bivariate color palettes are available (besides the three main palette types: categorical, sequential, and diverging).
* Own color palettes can be loaded and analysed.
* Color for missing values are made explicit.
* Palettes are made consistent with each other to enable comparison. For instance, black and white are (by default) removed from categorical palettes. Another standard that we adapt to is that all sequential palettes go from light to dark and not the other way round.
* There is native support for **ggplot2** and **tmap** (as of the
upcoming version 4).
* There are a couple of exporting options, including (bibtex) citation.## Feedback welcome!
* Is everything working as expected?
* Do you miss certain palettes?
* Do you have ideas for improvement how to measure palette properties?
Let us know! (via github issues)