colors3d

R package for 2d and 3d color legends

https://github.com/matthewkling/colors3d

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.3%) to scientific vocabulary
Last synced: 9 months ago · JSON representation

Repository

R package for 2d and 3d color legends

Basic Info
Statistics
  • Stars: 3
  • Watchers: 1
  • Forks: 2
  • Open Issues: 0
  • Releases: 1
Created over 10 years ago · Last pushed over 2 years ago
Metadata Files
Readme Changelog License

README.Rmd

---
output: github_document
---



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

# colors3d





This R package provides functions to help generate two-dimensional and three-dimensional color gradient legends.

The three main functions, `colors3d`, `colors2d`, and `colorwheel2d` generate a color for each row of a user-supplied data set with 2-3 columns. These can then be used for plotting in various ways.

## Installation

You can install colors3d from GitHub with `devtools::install_github("matthewkling/colors3d")` or from CRAN with `install.packages("colors3d")`.

## Examples

Here's a simple application of the three color mapping functions. This example uses tidyverse, but this would all work in base R as well:

```{r example, warning=FALSE, message=FALSE}
library(colors3d)
library(tidyverse)

# simulate a 3D data set
d <- expand_grid(x = 1:20, y = 1:20, z = 1:4)

# define and plot some 2D color mappings
d$colors2d <- colors2d(d[, 1:2])
d$colorwheel2d <- colorwheel2d(d[, 1:2])
d %>%
      gather(mapping, color, colors2d, colorwheel2d) %>%
      ggplot(aes(x, y, fill = color)) +
      facet_wrap(~mapping) +
      geom_raster() +
      scale_fill_identity()

# define and plot a 3D color mapping
d$color3d <- colors3d(d[, 1:3])
d %>%
      ggplot(aes(x, y, fill = color3d)) +
      facet_wrap(~z, nrow = 1, labeller = label_both) +
      geom_raster() +
      scale_fill_identity()
```
In a more realistic application, we often want to create a pair of plots for a given visualization: a "legend" in which the x and y dimensions match those used to create the color mapping, and a second plot in which the colors are then displayed in a different data space. This allows users to understand relationships among four dimensions of the data (or 5, if a 3D color mapping is used). Let's use the `storms` dataset (from dplyr) as an example, with hurricane windspeed, size, longitude, and latitude as our variables of interest:

```{r example2, warning=FALSE, message=FALSE}
d <- na.omit(storms)
d$color <- colors2d(select(d, wind, hurricane_force_diameter),
                    xtrans = "rank", ytrans = "rank")

p1 <- ggplot(d, aes(wind, hurricane_force_diameter, color = color)) +
      geom_point() +
      scale_color_identity()
p2 <- ggplot() +
      geom_polygon(data = map_data("state"), 
                   aes(long, lat, group = group)) +
      geom_path(data = d, 
                aes(long, lat, color = color,
                    group = paste(name, year))) +
      scale_color_identity() +
      coord_cartesian(xlim = range(d$long),
                      ylim = range(d$lat))

library(patchwork)
p1 + p2
```

Owner

  • Name: Matthew Kling
  • Login: matthewkling
  • Kind: user
  • Company: University of Vermont

Macroecologist and conservation biogeographer. Postdoc at UVM.

GitHub Events

Total
Last Year

Packages

  • Total packages: 1
  • Total downloads:
    • cran 237 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
  • Total maintainers: 1
cran.r-project.org: colors3d

Generate 2D and 3D Color Palettes

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 237 Last month
Rankings
Dependent packages count: 28.9%
Dependent repos count: 37.0%
Average: 50.9%
Downloads: 86.8%
Maintainers (1)
Last synced: 10 months ago