[R] grDevices::hcl.colors using two colours: Bug or Feature?

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Fri Apr 28 11:51:32 CEST 2023


Às 06:01 de 28/04/2023, Stevie Pederson escreveu:
> Hi,
> 
> I'm not sure if this is a bug or a feature, but after updating to Rv4.3, if
> requesting two colours from hcl.colors() you now get the same colour twice.
> This occurs for all palettes I've tried. My reprex:
> 
> hcl.colors(2, "Vik")
> [1] "#F1F1F1" "#F1F1F1"
> 
> As I have multiple workflows I run repeatedly with A vs B comparisons, this
> has just broken the visualisations in many of them. Obviously a
> workaround is hcl.colors(3, "Vik")[c(1, 3)] but this seems rather
> unintuitive.
> 
> Thanks in advance,
> 
> Stevie
> 
> sessionInfo()
> R version 4.3.0 (2023-04-21)
> Platform: x86_64-pc-linux-gnu (64-bit)
> Running under: Ubuntu 20.04.6 LTS
> 
> Matrix products: default
> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
> 
> locale:
>   [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C
>   [3] LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8
>   [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8
>   [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C
>   [9] LC_ADDRESS=C               LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C
> 
> time zone: Australia/Adelaide
> tzcode source: system (glibc)
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> 
> loaded via a namespace (and not attached):
> [1] compiler_4.3.0 tools_4.3.0
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Hello,

I cannot reproduce this on Windows.


hcl.colors(2, "Vik")
# [1] "#002E60" "#3E2000"

clrs <- sapply(hcl.pals(), \(p) hcl.colors(2, p))
any(apply(clrs, 2, \(x) x[1] == x[2]))
# [1] FALSE

sessionInfo()
# R version 4.2.3 (2023-03-15 ucrt)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 22621)
#
# Matrix products: default
#
# locale:
# [1] LC_COLLATE=Portuguese_Portugal.utf8  LC_CTYPE=Portuguese_Portugal.utf8
# [3] LC_MONETARY=Portuguese_Portugal.utf8 LC_NUMERIC=C
# [5] LC_TIME=Portuguese_Portugal.utf8
#
# attached base packages:
# [1] stats     graphics  grDevices utils     datasets  methods   base
#
# loaded via a namespace (and not attached):
# [1] compiler_4.2.3


Hope this helps,

Rui Barradas



More information about the R-help mailing list