Add Correlation Coefficients with P-values to a Scatter Plot in R
In this article, we will discuss how to add correlation coefficients with P-value to a scatter plot in the R Programming Language.
To add correlation coefficient with P-value to a scatter plot, we use the stat_cor() function of the ggpubr package in the R Language. The ggpubr package provides some easy-to-use functions for creating and customizing ggplot2 plots. The stat_cor() function is used to add correlation coefficients with p-values to a scatter plot. The stat_cor() function takes method as an argument to decide which correlation coefficient we need to add on scatter plot, for example, Pearson, Spearman, or Kendall coefficient. To adjust the position of the label on the scatter plot, we use the label.x and label.y argument.
plot + stat_cor( method, label.x, label.y )
- method: determines the method used for correlation coefficient, such as, Pearson, Spearman or Kendall.
- label.x: determines the x-axis position of label.
- label.y: determines the y-axis position of label.
Example 1: Pearson correlation coefficient
Here, is a scatter plot with the Pearson correlation coefficient.
Example 2: Spearman correlation coefficient
Here, is a scatter plot with the Spearman correlation coefficient.