Home > database >  R: expression() in ggplot returns Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x
R: expression() in ggplot returns Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x

Time:11-26

I have recently updated R and Rstudio to versions 4.2.2 and 2022.07.2, respectively.

I am running some scripts that I used to run nicely with previous versions, without any Error.

Now I get this error any time I try to plot a graph that I make using ggplot which contains expression() in labs():

    plt1 <- ggplot(MyData,
                  aes(x=A, y=B)) 
      geom_point(aes(fill=C),
      size=3,
      shape =21) 
      labs(
        y = expression(beta ~ "(\211)"),
        x = "A",
        fill = "Banana") 
      theme_bw()
    
    plot(plt1)
    
    >Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
      invalid multibyte string at '<89>)'

The plot is showed if I remove expression()

CodePudding user response:

The issue was made by the code \211 (that is used to print the permill symbol), which in the new version of R (I guess) returns the error. Instead, it must be used \u2030 code.

I have found the solution here: https://github.com/brianstock/MixSIAR/issues/26

  • Related