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

Stevie Pederson @tephen@peder@on@@u @end|ng |rom gm@||@com
Fri Apr 28 13:12:57 CEST 2023


Thank you all for the rapid responses & testing. I was aware of the n>=3
limit in RColorBrewer::brewer.pal so wasn't quite sure if it was a new
constraint introduced intentionally. Glad to have been helpful in finding
this too.

All the best

On Fri, 28 Apr 2023 at 19:53, Rui Barradas <ruipbarradas using sapo.pt> wrote:

> Às 11:07 de 28/04/2023, Achim Zeileis escreveu:
> > This was introduced in 4.3.0 (hence Rui cannot reproduce it in 4.2.3).
> >
> > It's a bug and was introduced when fixing this other bug:
> >
> > https://bugs.R-project.org/show_bug.cgi?id=18476
> > https://hypatia.math.ethz.ch/pipermail/r-help/2023-February/476960.html
> >
> > Apparently, it only affects the case with n = 2 for diverging and
> > divergingx palettes. The culprit is this line:
> >
> > i <- if(n2 == 1L) 0 else seq.int(1, by = -2/(n - 1), length.out = n2)
> >
> > I think n2 == 1L is not the right condition and we need to distinguish n
> > = 1 and n = 2.
> >
> > Will have a closer look...
> >
> > Thanks for reporting this!
> > Achim
> >
> > On Fri, 28 Apr 2023, Rui Barradas wrote:
> >
> >> À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
> >>
> >> ______________________________________________
> >> 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,
>
> Right! I ran the wrong R version, here it is with R 4.3.0.
> The bug is now reproducible on Windows 11.
>
>
> hcl.colors(2, "Vik")
> # [1] "#F1F1F1" "#F1F1F1"
>
> clrs <- sapply(hcl.pals(), \(p) hcl.colors(2, p))
> any(apply(clrs, 2, \(x) x[1] == x[2]))
> # [1] TRUE
>
> sum(apply(clrs, 2, \(x) x[1] == x[2]))
> # [1] 35
>
> which(apply(clrs, 2, \(x) x[1] == x[2]))
> #      Blue-Red    Blue-Red 2    Blue-Red 3     Red-Green  Purple-Green
> #            80            81            82            83            84
> #  Purple-Brown   Green-Brown Blue-Yellow 2 Blue-Yellow 3  Green-Orange
> #            85            86            87            88            89
> #  Cyan-Magenta        Tropic          Broc          Cork           Vik
> #            90            91            92            93            94
> #        Berlin        Lisbon        Tofino         Earth          Fall
> #            95            96            97            99           100
> #        Geyser      TealRose         Temps          PuOr          RdBu
> #           101           102           103           104           105
> #          RdGy          PiYG          PRGn          BrBG        RdYlBu
> #           106           107           108           109           110
> #        RdYlGn      Spectral      Zissou 1       Cividis          Roma
> #           111           112           113           114           115
>
> sessionInfo()
> # R version 4.3.0 (2023-04-21 ucrt)
> # Platform: x86_64-w64-mingw32/x64 (64-bit)
> # Running under: Windows 11 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
> #
> # time zone: Europe/Lisbon
> # tzcode source: internal
> #
> # attached base packages:
> # [1] stats     graphics  grDevices utils     datasets  methods   base
> #
> # loaded via a namespace (and not attached):
> # [1] compiler_4.3.0
>
>
> Hope this helps,
>
> Rui Barradas
>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list