1

I try to use ggscatter() function from ggpubr package with the following code

ggscatter(mtcars, 
             x = "hp", y = "carb", 
             cor.coef = TRUE, cor.method = "spearman", 
             xlab = "x1", ylab = "x2")

but I get the following error.

Error in parse(text = text[[i]]) : :1:16: unexpected ',' 1: italic(R)~=~0,

Thanks in advance for the help.

Vincenzo
  • 145
  • 1
  • 6

2 Answers2

1

Not sure about your question as your code is working fine.

Sample data:

data(mtcars)

Sample code:

library(ggpubr)

ggscatter(mtcars, 
          x = "hp", y = "carb", 
          cor.coef = TRUE, cor.method = "spearman", 
          xlab = "x1", ylab = "x2")

Plot:

enter image description here

Rfanatic
  • 2,224
  • 1
  • 5
  • 21
  • Thanks, now I know its a singular problem of my system. I hope someone can come to a possible solution starting from the error message. – Vincenzo Mar 13 '22 at 16:00
  • 1
    It is very likely to be a problem with you having set your output decimal to a comma with options(OutDec = ","). See my answer. – Alex Nov 15 '22 at 13:03
1

I think the most likely answer to your problem is that you have set your output decimal to a comma with options(OutDec = ",") I had the exact same problem. Here is my question with the following answer: Error in parse(text ...) unexpected comma "," when plotting ggplot with ggpubr::stat_cor and output decimal set to comma (options(OutDec = ","))

This is a bug in the package ggpubr as it cannot handle commas as decimal seperators. For more information see here or in the comments:

MrFlick: Specifically I think it's in this line https://github.com/kassambara/ggpubr/blob/ac5a01f586a5f0b47260fed071e79be36ef3f8ea/R/stat_cor.R#L207 . Those values should be wrapped in quotes to prevent the parsing error. And the problem with the persistent decimal point in the p-values comes from https://github.com/kassambara/ggpubr/blob/ac5a01f586a5f0b47260fed071e79be36ef3f8ea/R/stat_cor.R#L219 . It doesn't look like the package really support a comma separator. –

However, there is a workaround (pointed out by @MrFlick) by passing the argument , output.type="text" in the stat_cor function e.g.:

stat_cor(show.legend = F ,label.y = c(18), method = "pearson", output.type="text") However, there is an edge case where this does not work, if p < 2.2e-16 (as with the example data) as the value of p is passed as a string and not a number. Otherwise it works though.

Alex
  • 96
  • 6