gene expression, correlation, RNAseq
1
0
Entering edit mode
23 months ago
Rob ▴ 170

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 • 907 views
ADD COMMENT
4
Entering edit mode
23 months ago
Trivas ★ 1.8k

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").
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY

Login before adding your answer.

Traffic: 1318 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6