knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
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.
This is a basic example which shows you how to create a flower plot from an appropriately structured data set:
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.
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:
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)
You can install the development version of flowers from GitHub with:
devtools::install_github("mbjones/flowers")
You can install the released version of flowers from CRAN with:
install.packages("flowers")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.