Skip to content

Commit

Permalink
Use palette functions from khroma
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Jul 26, 2024
1 parent 69eecaf commit d86178d
Show file tree
Hide file tree
Showing 30 changed files with 1,895 additions and 1,849 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ Imports:
arkhe (>= 1.6.0),
graphics,
grDevices,
khroma (>= 1.13.0),
methods,
stats,
utils
Suggests:
folio (>= 1.4.0),
khroma (>= 1.12.0),
knitr,
markdown,
rsvg,
Expand All @@ -52,7 +52,7 @@ VignetteBuilder:
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Collate:
'AllClasses.R'
'AllGenerics.R'
Expand Down
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ S3method(labels,DiversityIndex)
S3method(labels,RarefactionIndex)
S3method(plot,DiversityIndex)
S3method(plot,RarefactionIndex)
export(color)
export(palette_color_continuous)
export(palette_color_discrete)
export(palette_color_picker)
export(remove_NA)
export(remove_constant)
export(remove_zero)
Expand Down Expand Up @@ -74,6 +78,10 @@ importFrom(arkhe,remove_zero)
importFrom(arkhe,replace_NA)
importFrom(arkhe,replace_zero)
importFrom(arkhe,sparsity)
importFrom(khroma,color)
importFrom(khroma,palette_color_continuous)
importFrom(khroma,palette_color_discrete)
importFrom(khroma,palette_color_picker)
importFrom(methods,.valueClassTest)
importFrom(methods,as)
importFrom(methods,callGeneric)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# tabula 3.1.0.9000
## Internals
* Use palette functions from **khroma**.

# tabula 3.1.0
## New classes and methods
Expand Down
2 changes: 1 addition & 1 deletion R/plot_diversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ setMethod(
## Graphical parameters
lwd <- list(...)$lwd %||% graphics::par("lwd")
lty <- list(...)$lty %||% graphics::par("lty")
col <- list(...)$col %||% grDevices::hcl.colors(n, "viridis")
col <- list(...)$col %||% color("discreterainbow")(n)
if (length(lwd) < n) lwd <- rep(lwd, length.out = n)
if (length(lty) < n) lty <- rep(lty, length.out = n)
if (length(col) < n) col <- rep(col, length.out = n)
Expand Down
9 changes: 6 additions & 3 deletions R/plot_heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ NULL
setMethod(
f = "plot_heatmap",
signature = signature(object = "matrix"),
definition = function(object, col = grDevices::hcl.colors(12, "YlOrBr", rev = TRUE),
definition = function(object,
col = color("YlOrBr")(12),
diag = TRUE, upper = TRUE, lower = TRUE,
freq = FALSE, margin = 1, fixed_ratio = TRUE,
axes = TRUE, legend = TRUE, ...) {
Expand All @@ -28,7 +29,8 @@ setMethod(
setMethod(
f = "plot_heatmap",
signature = signature(object = "data.frame"),
definition = function(object, col = grDevices::hcl.colors(12, "YlOrBr", rev = TRUE),
definition = function(object,
col = color("YlOrBr")(12),
diag = TRUE, upper = TRUE, lower = TRUE,
freq = FALSE, margin = 1, fixed_ratio = TRUE,
axes = TRUE, legend = TRUE, ...) {
Expand All @@ -47,7 +49,8 @@ setMethod(
setMethod(
f = "plot_heatmap",
signature = signature(object = "dist"),
definition = function(object, col = grDevices::hcl.colors(12, "YlOrBr", rev = TRUE),
definition = function(object,
col = color("YlOrBr")(12),
diag = FALSE, upper = FALSE, lower = !upper,
axes = TRUE, legend = TRUE, ...) {
object <- as.matrix(object)
Expand Down
3 changes: 1 addition & 2 deletions R/plot_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ prepare <- function(object, diag = TRUE, upper = TRUE, lower = TRUE,
breaks <- pretty(val, n = 5)
domain <- range(c(breaks, min_val, max_val))
midpoint <- if (is.null(midpoint) & min_val < 0 & max_val > 0) 0 else midpoint
pal <- palette_color_continuous(colors = palette, domain = domain,
midpoint = midpoint)
pal <- palette_color_continuous(colors = palette, domain = domain, midpoint = midpoint)
data$color <- if (length(palette) != length(val)) pal(val) else palette

## Clean data
Expand Down
2 changes: 1 addition & 1 deletion R/plot_rank.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ setMethod(
lwd <- list(...)$lwd %||% graphics::par("lwd")
lty <- list(...)$lty %||% graphics::par("lty")
cex <- list(...)$cex %||% graphics::par("cex")
col <- list(...)$col %||% grDevices::hcl.colors(n, "viridis")
col <- list(...)$col %||% color("discreterainbow")(n)
if (length(pch) < n) pch <- rep(pch, length.out = n)
if (length(lwd) < n) lwd <- rep(lwd, length.out = n)
if (length(lty) < n) lty <- rep(lty, length.out = n)
Expand Down
6 changes: 3 additions & 3 deletions R/plot_spot.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ setMethod(
f = "plot_spot",
signature = signature(object = "matrix"),
definition = function(object, type = c("ring", "plain"),
col = grDevices::hcl.colors(12, "YlOrBr", rev = TRUE),
col = color("YlOrBr")(12),
diag = TRUE, upper = TRUE, lower = TRUE,
freq = FALSE, margin = 1,
axes = TRUE, legend = TRUE, ...) {
Expand All @@ -32,7 +32,7 @@ setMethod(
f = "plot_spot",
signature = signature(object = "data.frame"),
definition = function(object, type = c("ring", "plain"),
col = grDevices::hcl.colors(12, "YlOrBr", rev = TRUE),
col = color("YlOrBr")(12),
diag = TRUE, upper = TRUE, lower = TRUE,
freq = FALSE, margin = 1,
axes = TRUE, legend = TRUE, ...) {
Expand All @@ -51,7 +51,7 @@ setMethod(
f = "plot_spot",
signature = signature(object = "dist"),
definition = function(object, type = c("ring", "plain"),
col = grDevices::hcl.colors(12, "YlOrBr", rev = TRUE),
col = color("YlOrBr")(12),
diag = FALSE, upper = FALSE, lower = !upper,
axes = TRUE, legend = TRUE, ...) {
# index_name <- attr(object, "method")
Expand Down
18 changes: 18 additions & 0 deletions R/reexport.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,21 @@ arkhe::remove_constant
#' @importFrom arkhe sparsity
#' @export
arkhe::sparsity

# REEXPORT FROM KHROMA

#' @importFrom khroma color
#' @export
khroma::color

#' @importFrom khroma palette_color_continuous
#' @export
khroma::palette_color_continuous

#' @importFrom khroma palette_color_discrete
#' @export
khroma::palette_color_discrete

#' @importFrom khroma palette_color_picker
#' @export
khroma::palette_color_picker
34 changes: 17 additions & 17 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.4.0 (2024-04-24)",
"runtimePlatform": "R version 4.4.1 (2024-06-14)",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand Down Expand Up @@ -100,19 +100,6 @@
},
"sameAs": "https://CRAN.R-project.org/package=folio"
},
{
"@type": "SoftwareApplication",
"identifier": "khroma",
"name": "khroma",
"version": ">= 1.12.0",
"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=khroma"
},
{
"@type": "SoftwareApplication",
"identifier": "knitr",
Expand Down Expand Up @@ -217,23 +204,36 @@
"name": "grDevices"
},
"5": {
"@type": "SoftwareApplication",
"identifier": "khroma",
"name": "khroma",
"version": ">= 1.13.0",
"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=khroma"
},
"6": {
"@type": "SoftwareApplication",
"identifier": "methods",
"name": "methods"
},
"6": {
"7": {
"@type": "SoftwareApplication",
"identifier": "stats",
"name": "stats"
},
"7": {
"8": {
"@type": "SoftwareApplication",
"identifier": "utils",
"name": "utils"
},
"SystemRequirements": null
},
"fileSize": "1567.133KB",
"fileSize": "1569.019KB",
"citation": [
{
"@type": "ScholarlyArticle",
Expand Down
Loading

0 comments on commit d86178d

Please sign in to comment.