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:
This is what I want but with correlation coefficient. the x axis is variable, the y axis is gene expression:
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.