1

How do you only display the correlation coefficient in ggpubr::stat_cor, and not the p-value? There doesn't seem to be an argument within stat_cor to specify only one statistic or the other. Is there some other creative work-around?

MeC
  • 463
  • 3
  • 17
  • 2
    `ggplot2` doesn't have a `stat_cor`. Which add-on package are you using? Maybe `ggpubr`? – Gregor Thomas Sep 25 '19 at 18:18
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Sep 25 '19 at 18:22
  • No, I'm using geom_point in ggplot, not ggpubr. – MeC Sep 25 '19 at 18:37
  • Echoing Gregor, there is no `ggplot2::stat_cor`; the ggplot2 package has no such function, whereas `ggpubr` does. – Jon Spring Sep 25 '19 at 19:06
  • ok, edited. the question still remains, how do you remove the p-value from stat_cor()? – MeC Sep 25 '19 at 19:45
  • 1
    can you try including: `aes(label = ..r.label..)` in `stat_cor`? this should show only the R value. https://github.com/kassambara/ggpubr/issues/188 – Ben Sep 26 '19 at 01:00
  • just including ..r.label.. worked, thank you! – MeC Sep 26 '19 at 17:47

1 Answers1

1

Following Ben's solution - I including a reproducible example. First let's use a simple example:

library('ggplot2')
library('ggpubr')
data(iris)

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width  )) +
geom_point() + theme_bw() +
stat_cor(method = "pearson")

enter image description here

Now, you wanted to display only the correlation coefficient, meaning R.

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width  )) +
geom_point() + theme_bw() +
stat_cor(method = "pearson", aes(label = ..r.label..))

Actually you can also calculate the R-value independently, and ad a textbox in the plot using annotate(example from iris database):

round(cor(iris$Sepal.Length, iris$Sepal.Width),2)

enter image description here

david
  • 439
  • 1
  • 4
  • 7