Entering edit mode
2.7 years ago
russell.stewart.j
▴
20
I'd like to generate a PCA of my bulk RNAseq data, coloured by each of my variables in the DESeq2 object "vsd". My current code looks like this (to generate a single plot):
pcaData <- plotPCA(vsd, intgroup=c("Age", "BlastRate"), returnData=TRUE)
percentVar <- round(100 * attr(pcaData, "percentVar"))
ggplot(pcaData, aes(PC1, PC2, color=Age, shape=BlastRate)) +
geom_point(size=3) +
xlab(paste0("PC1: ",percentVar[1],"% variance")) +
ylab(paste0("PC2: ",percentVar[2],"% variance")) +
geom_text(aes(label=name),hjust=-.2, vjust=0) +
ggtitle("Principal Component Analysis")
Can anyone suggest a method to loop through and swap "Age" with the other variable columns of vsd?
>head(colData(vsd),1)
DataFrame with 1 row and 14 columns
LibSize LibDiversity PercMapped Age SpermStatus SpConc SpMot Subject.Group PairedSample FertRate
<factor> <factor> <factor> <factor> <character> <factor> <factor> <factor> <factor> <factor>
sRNA_1 Low High High 42-46 unk unk unk Male-Male 2 Low
BlastRate RNABatch LibPrepBatch sizeFactor
<factor> <factor> <factor> <numeric>
sRNA_1 Low 1 6 0.929408
I tried your suggestion and got this error. I'm not sure why I get this error when running your loop but not when I run my code as above. Notably I'm working in Rstudio so each one of these code blocks is a chunk.
Note that intgroup in the first line needs to contain every element of colData that you might want to include. So you may as put them all in; there's no reason not to.
Also note the difference between aes() and aes_string(), how one takes barewords, and one takes quoted strings.
Yes sorry, BlastRate should be quoted "BlastRate" as noticed by swbarnes2