Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/Nowosad/rcartocolor

Implementation of the CARTOcolor palettes in R
https://github.com/Nowosad/rcartocolor

color-palette ggplot2 package r visualization

Last synced: about 1 month ago
JSON representation

Implementation of the CARTOcolor palettes in R

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
fig.height = 4
)
```

# rcartocolor

[![R-CMD-check](https://github.com/Nowosad/rcartocolor/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Nowosad/rcartocolor/actions/workflows/R-CMD-check.yaml)
[![codecov](https://codecov.io/gh/Nowosad/rcartocolor/branch/master/graph/badge.svg?token=tkiSWsEUYy)](https://codecov.io/gh/Nowosad/rcartocolor)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/rcartocolor)](https://cran.r-project.org/package=rcartocolor)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/rcartocolor)](https://cran.r-project.org/package=rcartocolor)

The goal of `rcartocolor` is to provide color schemes for maps and other graphics designed by [CARTO](https://carto.com/) as described at https://carto.com/carto-colors/.

## Installation

Get the released version from CRAN:

```{r cran-installation, eval = FALSE}
install.packages("rcartocolor")
```

Get the development version from github:

```{r gh-installation, eval = FALSE}
# install.packages("remotes")
remotes::install_github("Nowosad/rcartocolor")
```

## Examples

Display a CARTOcolor palette:

```{r example}
library(rcartocolor)
display_carto_pal(7, "Vivid")
```

Create a CARTOcolor palette:

```{r example2}
my_colors = carto_pal(7, "Burg")
my_colors
```

Display all of the CARTOcolor palettes:

```{r example3, fig.height=7, fig.width=6}
display_carto_all()
```

[Only display colorblind friendly palettes](https://jakubnowosad.com/colorblindcheck/articles/check_rcartocolor.html):

```{r example4, fig.height=6, fig.width=6}
display_carto_all(colorblind_friendly = TRUE)
```

### **ggplot2**

The **rcartocolor** package contains four **ggplot2** color scales: two for continuous data - `scale_fill_carto_c`, `scale_color_carto_c` and two for discrete data - `scale_fill_carto_d`, `scale_color_carto_d`:

```{r examplegg1}
# devtools::install_github("tidyverse/ggplot2")
library(sf)
library(spData)
library(ggplot2)
ggplot(world, aes(fill = lifeExp)) +
geom_sf(data = world) +
coord_sf(crs = "+proj=robin") +
scale_fill_carto_c(name = "Life expectancy: ",
type = "diverging", palette = "Earth", direction = -1) +
theme_void()
```

```{r examplegg2}
ggplot(world, aes(fill = region_un)) +
geom_sf(data = world) +
coord_sf(crs = "+proj=robin") +
scale_fill_carto_d(name = "Region: ", palette = "Safe") +
theme_void()
```

## Contributions

[Feel free to submit issues and enhancement requests.](https://github.com/Nowosad/rcartocolor/issues)