[R] bgroup not rendering properly

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Tue Dec 13 11:02:23 CET 2022


>>>>> Jinsong Zhao 
>>>>>     on Tue, 13 Dec 2022 17:07:00 +0800 writes:

    > I don

    >  On 2022/12/13 10:13, Derek Ogle wrote:
    >> bgroup() from plotmath does not render properly for
    >> me. For example
    >> 
    >> plot(0,xlim=c(0,1),ylim=c(0,1))
    >> text(0.3,0.5,expression(bgroup('(',atop(x,y),')')))
    >> text(0.7,0.5,expression(group('(',atop(x,y),')')))

Almost surely a  Windows-only problem i.e. bug,
See also the bug fixed yesterday, PR#18440,
https://bugs.r-project.org/show_bug.cgi?id=18440

Note that "rendering" of graphics strongly depends on your
graphics device (people no longer learn about nowadays).
Hence, use

   .Device
or
   dev.cur()

and report that along with your session info.

I bet that you will see that after

png("bgroup.png")  # or pdf("bgroup.pdf")
expression(bgroup('(',atop(x,y),')')
dev.off()

the resulting PNG or PDF will look fine,
even on Windows in R 4.2.2.

Martin


    >> 
    >> and
    >> 
    >> library(ggplot2) ggplot(mtcars, aes(wt, mpg)) +
    >> annotate("text", x=2.5, y=25,
    >> label="bgroup('(',atop(x,y),')')", parse=TRUE) +
    >> annotate("text", x=3.5, y=25,
    >> label="group('(',atop(x,y),')')", parse=TRUE)
    >> 
    >> both show a proper (though ugly) result from group() (the
    >> second text() or annotation()) but unrecognizable
    >> characters (rather than large parentheses) from bgroup().
    >> 
    >> This problematic result occurred for me when using
    >> v4.2.2, but not when using 4.2.0, 4.1.2, 4.1.0, or
    >> 4.0.5. My sessionInfo is further below.
    >> 
    >> I did ask this on stackoverflow
    >> <https://stackoverflow.com/questions/74738827/bgroup-does-not-render-properly-on-ggplot>
    >> where the resulting figures can be seen.
    >> 
    >> 
    >> ----
    >> R version 4.2.2 (2022-10-31 ucrt) Platform:
    >> x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10
    >> x64 (build 19044)
    >> 
    >> Matrix products: default
    >> 
    >> locale: [1] LC_COLLATE=English_United States.utf8 [2]
    >> LC_CTYPE=English_United States.utf8 [3]
    >> LC_MONETARY=English_United States.utf8 [4] LC_NUMERIC=C
    >> [5] LC_TIME=English_United States.utf8
    >> 
    >> attached base packages: [1] stats graphics grDevices
    >> utils datasets methods base
    >> 
    >> loaded via a namespace (and not attached): [1]
    >> compiler_4.2.2 tools_4.2.2
    > I don't see any problem, especially when outputing the
    > plot to a pdf file.

    > Best, Jinsong



More information about the R-help mailing list