Entering edit mode
16 months ago
Rob
▴
170
I am using the following code to create a correlation plot between genes and a continuous variable. It gives me the correlation coefficient (R) and p-value on the plot. I want this to:
- give me FDR values
- How can I get R values and FDR values in a csv or excel file, Not just written on the image of plot?
code:
library(ggplot2)
library(plyr)
library(reshape2)
dat <- read.csv("Gene_variable_file.csv", check.name = FALSE, stringsAsFactors = FALSE, header = T)
df <- as.data.frame(dat)
# Basic scatter plot
ex <- melt(df, id.vars="continousVariable")
colnames(ex) <- c("continousVariable", "gene", "exprs")
#######################
####
ggscatter(ex, x = "continousVariable", y = "exprs",
add = "reg.line",
add.params = list(color = "blue", fill = "lightgray"),
color = "black", palette = "jco", fill = "lightgray",
#shape = "cyl",
fullrange = TRUE,
rug = TRUE, facet.by = "gene", cor.coef = T,
title = "Sarco-Specific DEGs-SMA Correlation-FEMALE",
conf.int = TRUE,
cor.coeff.args = list(),
cor.method = "spearman",
cor.coef.coord = c(NULL, NULL),
cor.coef.size = 4,
)+
geom_vline(xintercept = 102, colour="red", linetype = "longdash")
This is how my data look like:
Thank you. It tried
broom
from this link: https://cran.r-project.org/web/packages/broom/vignettes/broom.htmlBut which method I should use?
ttest
?glm
?lm
? I used lm and I got all my p-values 1,1,1,1... which cannot be correct.which one from the following code will be my data in broom code?"
dat
" or "ex
"I used
ex
as my data inbroom
By the looks of things, it would be
ex
. You'd need togroup_by
gene in some way. I've always usedgroup_by
, but this vignette suggestsnest
ing https://cran.r-project.org/web/packages/broom/vignettes/broom_and_dplyr.html.If you want to do pearson correlation, then
lm
should work fine, as the p-value on a linear model is identical to the p-value of a pearson's correlation. I'm not sure you can do spearman's that way though. You can usecor.test(method="spearman")
though.I agree that it is unlikely that all your p-values or 1. However, all your FDRs/adjusted p-values being 1 is entirely possible.