4

The results of bgroup from plotmath do not seem to render properly as a ggplot2 annotation. For example ...

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)

... produces the following graph for me ...

enter image description here

Note how the bgroup rendering on the left does not have large parentheses like I would expect (and worked in some previous version of R), whereas the reqular group rendering to the right does seem to work.

Am I missing a font? Something else?

I am using R 4.2.2 and ggplot2 3.4.0.

EDITS:

  1. The code above worked properly in R versions 4.0.5, 4.1.0, 4.1.2, and 4.2.0 (and 3.6.3 according to Jamie in the comments .. but not on Linux according to an answer on R-help).
  2. The issue does not seem related to ggplot2 as the same problem occurs with base graphics.
  3. The same issue occurs with R version 4.2.2 whether the code is run in RStudio or the RGui.
  4. The same issue occurs (in R version 4.2.2) when the plot is directed to a PNG but not when it is directed to a PDF.
plot(0,xlim=c(0,1),ylim=c(0,1))
text(0.5,0.5,expression(bgroup('(',atop(x,y),')')))

enter image description here

D Ogle
  • 407
  • 2
  • 13

1 Answers1

1

It's working fine for me on Linux; I guess you guys are all using Windows? Note that "rendering" strongly depends on the graphics device. What is your .Device {after plotting}? I suggest a Windows graphapp font problem, similar to the one just fixed yesterday, also Windows-only: https://bugs.r-project.org/show_bug.cgi?id=18440

Martin Mächler
  • 4,619
  • 27
  • 27
  • 1
    I am using Windows. `.Device` is "windows" when run in the RGui and "RStudioGD" when run in RStudio. – D Ogle Dec 13 '22 at 14:06