This is a test version of Biostars. For the public version, visit https://www.biostars.org.
gene expression, correlation, RNAseq

Hi friends I want to create a scatter plot for correlation between each gene expression with a continuous variable (variable). I need to have coefficient values for each of the genes. I used the following code but it didn't give coefficient values. How can I get the correlation coefficient for each plot?

 data <- read.csv ("mydata.csv",check.name = FALSE, stringsAsFactors = FALSE, header = T)

    install.packages (ggpubr)
    library(ggplot2)
    library(plyr)
    library(reshape2)

    df <- as.data.frame(data)
    # Basic scatter plot
    ex <- melt(df, id.vars="gene")

    colnames(ex) <- c("gene", "variable","exprs")
    #####
    ggscatter(ex, x = "variable", y = "exprs",
              add = "reg.line",                         # Add regression line

              fullrange = TRUE,                         # Extending the regression line
              rug = TRUE                                # Add marginal rug
    )+
      facet_wrap(~ gene, scales = "free") 
      stat_cor(method = "pearson", label.x = 3, label.y = 30)

This is what my data looks like. the first row(line) is the continuous variable:

datafile-SF

This is what I want but with correlation coefficient. the x axis is variable, the y axis is gene expression:

plotscorr-F

coefficient rnaseq expression correlation

1 answer

Your plotting commands ends with the facet_wrap line. If you add a + at the end, does that fix it?

You can also add the following arguments to the ggscatter call:

cor.coef    
logical value. If TRUE, correlation coefficient with the p-value will be added to the plot.

cor.coeff.args  
a list of arguments to pass to the function stat_cor for customizing the displayed correlation coefficients. For example: cor.coeff.args = list(method = "pearson", label.x.npc = "right", label.y.npc = "top").

wow You are right I added a + at the end of the facet_wrap line and this worked. You saved me Thank you so much.

Log in to answer this question.