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

https://github.com/nceas/flowers

R package for generating flower plots
https://github.com/nceas/flowers

Last synced: 4 months ago
JSON representation

R package for generating flower plots

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%"
)
```

# flowers

[![CRAN status](https://www.r-pkg.org/badges/version/flowers)](https://CRAN.R-project.org/package=flowers)
[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)

Flowers is a package for generating flower plots. It was derived from code
from Jim Regetz at NCEAS, and then rewritten and extended by the OHI project.
This package formalizes the approach into an easily re-usable function
for generating custom flower plots for multiple scenarios.

## Quick Start

This is a basic example which shows you how to create a flower plot from an
appropriately structured data set:

```{r example, message=FALSE, warning=FALSE, fig.width=8, fig.height=8, out.width="70%"}
library(flowers)
data(ohi)
plot_flower(ohi, "OHI Example Flower")
```

Currently `plot_flower()` expects particular column names and semantics, but
this could be made more flexible. See the structure of OHI for an example. In particular,
it uses columns `score`, `weight`, `label`, and `category` to create the plot.

By default the flower petals are colored proportionally to the `score` values as
show in the OHI example above. One can provide a color palette (`colors`) to the
`plot_flower()` function to control the gradient used.

The `weight` variable controls the relative widths of the petals, and should range
from 0 to 1. The petal labels are taken from the `label` variable, and the
grouping category labels are taken from the `category` variable. Other
columns in the data frame are ignored.

```{r ohi_structure, echo=FALSE}
str(ohi)
```

Alternatively, by setting `fixed_colors = TRUE` you can also color the petals
with discrete colors determined by the `label` values, in which case
you will likely want to provide a `colors` palette with at least as many colors
as you have petals in the plot. Here's an example with four fixed petals, in
which we also provide only missing values to `category` so that no grouping
labels are used:

```{r fair_plot, message=FALSE, warning=FALSE, fig.width=8, fig.height=8, out.width="70%"}
library(dplyr)
df <- data.frame(order = c(1, 4, 3, 2),
score = c(90, 80, 70, 60),
weight = c(1, 1, 1, 1),
goal = c("F", "A", "I", "R"),
label = c("Findable", "Accessible", "Interoperable", "Reusable"),
category = c(NA, NA, NA, NA),
stringsAsFactors = FALSE) %>% arrange(order)
d1_colors <- c( "#c70a61", "#ff582d", "#1a6379", "#60c5e4")
plot_flower(df, title = "FAIR Metrics", fixed_colors=TRUE, colors = d1_colors)
```

## Installation

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

``` r
devtools::install_github("mbjones/flowers")
```

You can install the released version of flowers from [CRAN](https://CRAN.R-project.org) with:

``` r
install.packages("flowers")
```

[![nceas_footer](https://www.nceas.ucsb.edu/files/newLogo_0.png)](http://www.nceas.ucsb.edu)