Skip to content

Commit

Permalink
Merge pull request #11 from ropensci/colors
Browse files Browse the repository at this point in the history
adds cpr_make_pal()
  • Loading branch information
joelnitta authored Sep 27, 2022
2 parents 94a4345 + f0b1a6d commit ec624d4
Show file tree
Hide file tree
Showing 22 changed files with 447 additions and 39 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ Suggests:
withr,
fs,
readr,
usethis
usethis,
scales,
colorBlindness
Config/testthat/edition: 3
Depends:
R (>= 4.1.0)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(cpr_classify_endem)
export(cpr_classify_signif)
export(cpr_make_pal)
export(cpr_iter_test)
export(cpr_rand_comm)
export(cpr_rand_test)
Expand Down
70 changes: 70 additions & 0 deletions R/cpr_make_pal.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#' Make a palette of colors for plotting CANAPE results
#'
#' Palettes can also be loaded by name directly (see "Other colors" below).
#'
#' Palettes with the name 'mishler2014' correspond to colors used in Mishler et
#' al. 2014. This color scheme has been widely used to show CANAPE
#' results, but some colors may not be distinguishable to people with color
#' vision deficiency (CVD).
#'
#' Palettes with the name 'canaper1' or 'canaper2' are based on the Okabe-Ito
#' palette (endemism; Okabe & Ito 2002) or RColorBrewer (significance) and
#' should be CVD-friendly.
#'
#' Names of colors correspond to either endemism type or
#' *p*-rank output by [cpr_classify_endem()] or [cpr_classify_signif()],
#' respectively.
#'
#' @param name Character vector of length 1; name of palette to select. Must be
#' one of 'mishler2014', 'canaper1', or 'canaper2'
#' @param type Character vector of length 1; type of palette to select. Must be
#' one of 'endem' (endemism) or 'signif' (*p*-rank significance)
#' @references Mishler, B., Knerr, N., González-Orozco, C. et al. (2014)
#' Phylogenetic measures of biodiversity and
#' neo- and paleo-endemism in Australian Acacia. Nat Commun, 5: 4473.
#' \doi{10.1038/ncomms5473}
#' @references Okabe, M., & Ito, K. (2002) Color
#' Universal Design (CUD) - How to make figures and presentations that are
#' friendly to Colorblind people. J*FLY Data
#' Depository for Drosophila Researchers. <https://jfly.uni-koeln.de/color>
#' @return Named character vector; color hex codes
#' @family colors
#' @export
#' @examples
#' cpr_make_pal("mishler2014", "endem")
#' cpr_make_pal("canaper1", "endem")
#' scales::show_col(cpr_make_pal("mishler2014", "endem"))
cpr_make_pal <- function(name, type) {
# Check input: name
assertthat::assert_that(assertthat::is.string(name))
assertthat::assert_that(assertthat::noNA(name))
assertthat::assert_that(
name %in% c("mishler2014", "canaper1", "canaper2"),
msg = "'name' may only include 'mishler2014', 'canaper1', or 'canaper2'"
)
# Check input: type
assertthat::assert_that(assertthat::is.string(type))
assertthat::assert_that(assertthat::noNA(type))
assertthat::assert_that(
type %in% c("endem", "signif"),
msg = "'type' may only include 'endem' or 'signif'"
)
if (type == "endem" && name == "mishler2014") {
return(mishler_endem_cols)
}
if (type == "endem" && name == "canaper1") {
return(cpr_endem_cols)
}
if (type == "endem" && name == "canaper2") {
return(cpr_endem_cols_2)
}
if (type == "signif" && name == "mishler2014") {
return(mishler_signif_cols)
}
if (type == "signif" && name == "canaper1") {
return(cpr_signif_cols)
}
if (type == "signif" && name == "canaper2") {
return(cpr_signif_cols_2)
}
}
71 changes: 57 additions & 14 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,58 +124,101 @@
#' biod_results
"biod_results"

#' Color palette for plotting results of randomization test
#' Original color palette for plotting results of CANAPE
#'
#' Character vector with names corresponding to endemism types
#' and values corresponding to color codes. Original palette used by
#' Mishler et al. (2014). May not be distinguishable to people with
#' color-vision deficiency (CVD).
#'
#' @srrstats {G1.4} uses roxygen
#'
#' @family colors
#'
#' @references Mishler, B., Knerr, N., González-Orozco, C. et al. (2014)
#' Phylogenetic measures of biodiversity and neo- and paleo-endemism in
#' Australian Acacia. Nat Commun, 5: 4473. \doi{10.1038/ncomms5473}
#'
#' @examples
#' mishler_signif_cols
#' scales::show_col(mishler_signif_cols)
"mishler_signif_cols"

#' CVD-friendly color palette for plotting results of randomization test
#'
#' Character vector with names corresponding to significance levels
#' and values corresponding to color codes.
#'
#' @srrstats {G1.4} uses roxygen
#'
#' @family colors
#'
#' @examples
#' cpr_signif_cols
#' \dontrun{
#' scales::show_col(cpr_signif_cols)
#' }
"cpr_signif_cols"

#' Color palette for plotting results of randomization test, version 2
#' CVD-friendly color palette for plotting results of randomization test,
#' version 2
#'
#' Character vector with names corresponding to significance levels and values
#' corresponding to color codes, with "not significant" colored grey.
#'
#' @srrstats {G1.4} uses roxygen
#'
#' @family colors
#'
#' @examples
#' cpr_signif_cols_2
#' \dontrun{
#' scales::show_col(cpr_signif_cols_2)
#' }
"cpr_signif_cols_2"

#' Color palette for plotting results of CANAPE
#' Original color palette for plotting results of CANAPE
#'
#' Character vector with names corresponding to endemism types
#' and values corresponding to color codes.
#' and values corresponding to color codes. Original palette used by
#' Mishler et al. (2014). May not be distinguishable to people with
#' color-vision deficiency (CVD).
#'
#' @srrstats {G1.4} uses roxygen
#'
#' @family colors
#'
#' @references Mishler, B., Knerr, N., González-Orozco, C. et al. (2014)
#' Phylogenetic measures of biodiversity and neo- and paleo-endemism in
#' Australian Acacia. Nat Commun, 5: 4473. \doi{10.1038/ncomms5473}
#'
#' @examples
#' mishler_endem_cols
#' scales::show_col(mishler_endem_cols)
"mishler_endem_cols"

#' CVD-friendly color palette for plotting results of CANAPE
#'
#' Character vector with names corresponding to endemism types
#' and values corresponding to color codes. Should be distinguishable to
#' people with color-vision deficiency (CVD).
#'
#' @srrstats {G1.4} uses roxygen
#'
#' @family colors
#'
#' @examples
#' cpr_endem_cols
#' \dontrun{
#' scales::show_col(cpr_endem_cols)
#' }
"cpr_endem_cols"

#' Color palette for plotting results of CANAPE, version 2
#' CVD-friendly color palette for plotting results of CANAPE, version 2
#'
#' Character vector with names corresponding to endemism types and values
#' corresponding to color codes, with "not significant" colored grey.
#' corresponding to color codes, with "not significant" colored grey. Should
#' be distinguishable to people with color-vision deficiency (CVD).
#'
#' @srrstats {G1.4} uses roxygen
#'
#' @family colors
#'
#' @examples
#' cpr_endem_cols_2
#' \dontrun{
#' scales::show_col(cpr_endem_cols_2)
#' }
"cpr_endem_cols_2"
13 changes: 10 additions & 3 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ reference:
- title: Classification
desc: Functions to classify the results of the randomization test
- contents: starts_with("cpr_classify")
- title: Data
- title: Datasets
desc: Datasets included in this package
- contents:
- acacia
- biod_example
- phylocom
- biod_results
- title: Color palettes
desc: Palettes for plotting classification results
- contents: matches("_cols")
desc: Colors for plotting classification results
- contents:
- cpr_make_pal
- mishler_endem_cols
- cpr_endem_cols
- cpr_endem_cols_2
- mishler_signif_cols
- cpr_signif_cols
- cpr_signif_cols_2
37 changes: 34 additions & 3 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "R",
"url": "https://r-project.org"
},
"runtimePlatform": "R version 4.2.0 (2022-04-22)",
"runtimePlatform": "R version 4.2.1 (2022-06-23)",
"author": [
{
"@type": "Person",
Expand Down Expand Up @@ -249,6 +249,30 @@
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=usethis"
},
{
"@type": "SoftwareApplication",
"identifier": "scales",
"name": "scales",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=scales"
},
{
"@type": "SoftwareApplication",
"identifier": "colorBlindness",
"name": "colorBlindness",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=colorBlindness"
}
],
"softwareRequirements": {
Expand Down Expand Up @@ -385,7 +409,7 @@
},
"SystemRequirements": null
},
"fileSize": "280.144KB",
"fileSize": "9701.825KB",
"citation": [
{
"@type": "SoftwareSourceCode",
Expand All @@ -410,6 +434,13 @@
}
],
"releaseNotes": "https://github.com/ropensci/canaper/blob/master/NEWS.md",
"readme": "https://github.com/ropensci/canaper/blob/main/README.md",
"contIntegration": ["https://github.com/ropensci/canaper/actions", "https://codecov.io/gh/ropensci/canaper?branch=main"],
"developmentStatus": "https://www.repostatus.org/#wip"
"developmentStatus": "https://www.repostatus.org/#active",
"review": {
"@type": "Review",
"url": "https://github.com/ropensci/software-review/issues/475",
"provider": "https://ropensci.org"
},
"keywords": ["biodiversity", "canape"]
}
41 changes: 33 additions & 8 deletions data-raw/cpr_cols.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@ cpr_signif_cols_2 <-

usethis::use_data(cpr_signif_cols_2, overwrite = TRUE)

# - Randomization, Mishler 2014
mishler_signif_cols <-
c(
"< 0.01" = "#7D170E", # Dark red
"< 0.025" = "#E73323", # Light red
"not significant" = "#FAFAD6", # Beige
"> 0.975" = "#5577F7", # Light blue
"> 0.99" = "#2E4086" # Dark blue
)

usethis::use_data(mishler_signif_cols, overwrite = TRUE)

# - Mishler 2014
# original biodiverse colors
mishler_endem_cols <-
c(
"neo" = "#E73323",
"paleo" = "#5577F7",
"not significant" = "#FAFAD6",
"mixed" = "#BF84F8",
"super" = "#8E25F6"
)

usethis::use_data(mishler_endem_cols, overwrite = TRUE)

# - CANAPE (Okabe-Ito CVD safe)
cpr_endem_cols <-
c(
Expand Down Expand Up @@ -55,8 +80,8 @@ usethis::use_data(cpr_endem_cols_2, overwrite = TRUE)
# - cpr_signif_cols
tibble(
var_a = names(cpr_signif_cols),
var_b = 1:length(cpr_signif_cols),
var_c = 1:length(cpr_signif_cols),
var_b = seq_along(cpr_signif_cols),
var_c = seq_along(cpr_signif_cols),
) |>
ggplot(aes(x = var_b, y = var_c, color = var_a)) +
geom_point(size = 3) +
Expand All @@ -68,8 +93,8 @@ colorBlindness::cvdPlot()
# - cpr_signif_cols_2
tibble(
var_a = names(cpr_signif_cols_2),
var_b = 1:length(cpr_signif_cols_2),
var_c = 1:length(cpr_signif_cols_2),
var_b = seq_along(cpr_signif_cols_2),
var_c = seq_along(cpr_signif_cols_2),
) |>
ggplot(aes(x = var_b, y = var_c, color = var_a)) +
geom_point(size = 3) +
Expand All @@ -81,8 +106,8 @@ colorBlindness::cvdPlot()
# - cpr_endem_cols
tibble(
var_a = names(cpr_endem_cols),
var_b = 1:length(cpr_endem_cols),
var_c = 1:length(cpr_endem_cols),
var_b = seq_along(cpr_endem_cols),
var_c = seq_along(cpr_endem_cols),
) |>
ggplot(aes(x = var_b, y = var_c, color = var_a)) +
geom_point(size = 3) +
Expand All @@ -94,8 +119,8 @@ colorBlindness::cvdPlot()
# - cpr_endem_cols_2
tibble(
var_a = names(cpr_endem_cols_2),
var_b = 1:length(cpr_endem_cols_2),
var_c = 1:length(cpr_endem_cols_2),
var_b = seq_along(cpr_endem_cols_2),
var_c = seq_along(cpr_endem_cols_2),
) |>
ggplot(aes(x = var_b, y = var_c, color = var_a)) +
geom_point(size = 3) +
Expand Down
Binary file modified data/cpr_endem_cols.rda
Binary file not shown.
Binary file modified data/cpr_endem_cols_2.rda
Binary file not shown.
Binary file modified data/cpr_signif_cols.rda
Binary file not shown.
Binary file modified data/cpr_signif_cols_2.rda
Binary file not shown.
Binary file added data/mishler_endem_cols.rda
Binary file not shown.
Binary file added data/mishler_signif_cols.rda
Binary file not shown.
Loading

0 comments on commit ec624d4

Please sign in to comment.