View source: R/bioregion_colors.R
| bioregion_colors | R Documentation |
This function assigns colors to clusters in a bioregion.clusters object
using color palettes from the rcartocolor package. It
handles large numbers of clusters by assigning vivid colors to the most
important clusters (based on size), grey shades to less important clusters,
and optionally black to insignificant clusters.
bioregion_colors(
clusters,
palette = "Vivid",
cluster_ordering = "n_sites",
cutoff_insignificant = NULL
)
clusters |
An object of class |
palette |
A |
cluster_ordering |
A
Larger clusters (by the chosen criterion) receive vivid colors first. |
cutoff_insignificant |
A |
The function uses a two-step algorithm to assign colors:
Step 1: Identify insignificant clusters (if cutoff_insignificant is specified)
Insignificant clusters are those with a marginal size compared to others. This is a subjective threshold set by the user. All such clusters are assigned the color black (#000000) to minimize their visual impact. Clusters with values at or below the threshold are assigned black (#000000).
Step 2: Assign colors to significant clusters
Remaining clusters are ranked by the cluster_ordering criterion:
Top clusters (up to 12): Receive distinct colors from the chosen palette. This limit is because above 12 the human eye struggles to distinguish between colors.
Remaining clusters (beyond top 12): Receive shades of grey from light (#CCCCCC) to dark (#404040), maintaining visual distinction but with less prominence.
Multiple partitions: If the cluster object contains multiple partitions (e.g., from hierarchical clustering with different k values), colors are assigned independently for each partition. Each partition gets its own color scale optimized for the number of clusters in that partition.
A modified bioregion.clusters object with two additional elements:
colors: A list where each element corresponds to a partition
(bioregionalization). Each list element is a data.frame with two columns:
cluster (character): Cluster identifier for that partition
color (character): Hex color code (e.g., "#FF5733")
clusters_colors: A data.frame with the same structure as the
clusters element, but with cluster IDs replaced by their corresponding
hex color codes for direct use in plotting functions.
The colored cluster object can be directly used with map_bioregions(),
which will automatically detect and apply the color scheme when present.
Boris Leroy (leroy.boris@gmail.com)
Maxime Lenormand (maxime.lenormand@inrae.fr)
Pierre Denelle (pierre.denelle@gmail.com)
Color palettes from the rcartocolor package:
Nowosad J (2018). "CARTOColors: color palettes inspired by CARTO."
https://github.com/Nowosad/rcartocolor
For more details illustrated with a practical example, see the vignette: https://biorgeo.github.io/bioregion/articles/a5_1_visualization.html.
Associated functions: map_bioregions
data(fishmat)
data(fishsf)
# Basic example with few clusters
sim <- similarity(fishmat, metric = "Simpson")
clust <- netclu_greedy(sim)
clust_colored <- bioregion_colors(clust)
print(clust_colored)
## Not run:
# Map with automatic colors
map_bioregions(clust_colored, fishsf)
# Example with many clusters and cutoff
dissim <- similarity_to_dissimilarity(sim)
clust <- hclu_hierarclust(dissim,
optimal_tree_method = "best",
n_clust = 15)
clust_colored2 <- bioregion_colors(clust,
cluster_ordering = "n_sites",
cutoff_insignificant = 1)
map_bioregions(clust_colored2, fishsf)
# Example with different palette
clust_colored3 <- bioregion_colors(clust, palette = "Bold")
map_bioregions(clust_colored3, fishsf)
# Example with bipartite network
clust_bip <- netclu_greedy(fishdf, bipartite = TRUE)
clust_bip_colored <- bioregion_colors(clust_bip,
cluster_ordering = "n_both")
map_bioregions(clust_bip_colored, fishsf)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.