Using the mtcars dataset as an example, I am using "annotate" in the ggscatter function of ggpubr in R. This is my code:
library("ggpubr")
ggscatter(mtcars[mtcars$cyl == 8, ], x = "mpg", y = "qsec",
facet.by = "cyl", add = "reg.line", add.params = list(color = "black", fill = "lightgrey"),
conf.int = TRUE, cor.method = "spearman", cor.coef = TRUE, xlab = "mpg", ylab = "qsec")
+ annotate("text", x=10, y=15, parse=TRUE, label = paste0("n = ", with(mtcars, sum(mtcars$cyl == 8))))
It all works perfectly, except the annotation, specifically this part:
label = paste0("n = ", with(mtcars, sum(mtcars$cyl == 8)))
I would like the annotated text to read: "n = 14". However, it reads: "=(n, 14)". How come it looks so different? Any suggestions are very welcome. Thank you.