[R] grDevices::hcl.colors using two colours: Bug or Feature?
Achim Zeileis
Ach|m@Ze||e|@ @end|ng |rom u|bk@@c@@t
Fri Apr 28 17:44:28 CEST 2023
On Fri, 28 Apr 2023, Duncan Murdoch wrote:
> On 28/04/2023 6:18 a.m., Achim Zeileis wrote:
>> On Fri, 28 Apr 2023, Achim Zeileis wrote:
>>
>>> 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.
>>
>> I think the solution is simply to use n == 1L instead of n2 == 1L, both in
>> "diverging" (line 188 in hcl.colors.R) and "divergingx" (line 197).
>>
>> Duncan, maybe you can have a look at this as well?
>
> I agree that the two changes solve this problem. I couldn't spot any other
> places that would need fixing.
Great, thanks for checking. I reported the problem with the corresponding
patch at: https://bugs.R-project.org/show_bug.cgi?id=18523
Thanks & best wishes,
Achim
>>> 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.
>>>>
>>> ______________________________________________
>>> 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.
>>>
>> ______________________________________________
>> 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.
>
>
More information about the R-help
mailing list