aphalo / ggpmisc

R package ggpmisc is an extension to ggplot2 and the Grammar of Graphics
https://docs.r4photobiology.info/ggpmisc
100 stars 6 forks source link

use_label() with kendall tau #68

Closed bsuss closed 1 week ago

bsuss commented 2 months ago

I think I have encountered a bug for adding Kendall tau labels. I am trying to add Kendall's tau to scatterplots with the use_label() argument. This works for Pearson correlations and R2, however, when setting the method to "Kendall", the only stat I am able to successfully print is the P value. Attempting to print "tau" (or "R", "R.CI" which, is in the example documentation) returns this error:

Error in stat_correlation(): ! Problem while converting geom to grob. ℹ Error occurred in the 3rd layer. Caused by error in parse(): ! :1:1: unexpected '|' 1: | ^

This is code I am trying to use (I am using the ggpubr package, but this works for Pearson correlations)

myscatter <- data %>%
  ggscatter(
    x = "Age", y = "AUDIT_Total", 
    conf.int = TRUE,
    title = "AUDIT",
    ylab = "Total",
    xlab = "Age",
    cor.method = "kendall",
  ) + 
  stat_correlation(label.x= .1, mapping = use_label("tau", "p"), method = "kendall", vstep = 0.1, size = 10/.pt) 
smouksassi commented 2 months ago

works on my end

library(ggpubr) library(ggpmisc) mtcars %>% ggscatter( x = "disp", y = "mpg", conf.int = TRUE, title = "AUDIT", ylab = "Total", xlab = "Age", cor.coef = TRUE, # Add correlation coefficient. see ?stat_cor cor.coeff.args = list(method = "kendall", label.x = 3, label.sep = "\n") )+ stat_correlation(label.x= .9, mapping = use_label("tau", "p"), method = "kendall", vstep = 0.1, size = 10/.pt)

aphalo commented 1 week ago

Works also for me.