Error in ggbiplot
1
0
Entering edit mode
6.2 years ago
sandKings ▴ 30
'#plot PCA using all genes
require(genefilter)
require(calibrate)
require(RColorBrewer)
library(ggplot2)
install.packages("ggfortify")
library(ggfortify)
pca=prcomp(t(count_matrix))
pc1var <- round(summary(pca)$importance[2,1]*100, digits=1)
pc2var <- round(summary(pca)$importance[2,2]*100, digits=1)
pc1lab <- paste0("PC1 (",as.character(pc1var),"%)")
pc2lab <- paste0("PC2 (",as.character(pc2var),"%)")
pdf(pdfname)
pdfname <-paste(direc,method,"PCA_FPKM_all_genes.pdf",sep="")
autoplot(pca,data=comparison,colour='Group',xlab=pc1lab,ylab=pc2lab)+geom_text_repel(aes_string(x = "PC1", y = "PC2", label = "Name"))
dev.off()

All lines execute seemingly without error but

autoplot(pca,data=comparison,colour='Group',xlab=pc1lab,ylab=pc2lab)+geom_text_repel(aes_string(x = "PC1", y = "PC2", label = "Name"))

returns the following error:

Error in ggbiplot(plot.data = plot.data, loadings.data = loadings.data,  :   formal argument "xlab" matched by multiple actual arguments

checking the value of xlab returns

> xlab

function (label) 
{
    labs(x = label)
}
<environment: namespace:ggplot2>

Could someone please help me debug this?

Thanks!

I'm running this on RStudio 3.3.1

RStudio RNASeq PCAplot • 3.6k views
ADD COMMENT
1
Entering edit mode
6.2 years ago

These ggplot2 wrapper functions rarely work because the functioning of ggplot2 is more complex than other R functions. I think that you should aim to spend at least 1 full working day looking over the basics of ggplot2 so that you don't have to use these wrapper. Just my recommendation from experience.

I was able to plot a PCA bi-plot using the following:

count_matrix <- replicate(10, rnorm(20)) 
colnames(count_matrix) <- paste("sample", c(1:ncol(count_matrix)), sep="")

require(genefilter)
require(calibrate)
require(RColorBrewer)
library(ggplot2)
library(ggfortify)
require(ggrepel)

pca <- prcomp(t(count_matrix))
pc1var <- round(summary(pca)$importance[2,1]*100, digits=1)
pc2var <- round(summary(pca)$importance[2,2]*100, digits=1)
pc1lab <- paste0("PC1 (",as.character(pc1var),"%)")
pc2lab <- paste0("PC2 (",as.character(pc2var),"%)")
autoplot(pca, data=pca, xlab=pc1lab, ylab=pc2lab) + geom_text_repel(aes_string(x="PC1", y="PC2", label="colnames(count_matrix)"))

pca
free image hosting

ADD COMMENT
1
Entering edit mode

Thanks, Kevin! Let me try this and see.

ADD REPLY

Login before adding your answer.

Traffic: 2797 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