This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Problem on R when creating a PCA plot

A very weird thing is happening to me on R, the first time i installed "ggfortify" pacakage to create a PCA plot, the result was an Rplots.pdf file, it worked perfectly. The second time i used it, with the same exact data and commands, the result is an empty Rplots.pdf file and continues to happen every time i try to run R.

Can someone tell me what is the problem?

I used the following commands in R:

library("ggfortify")

q<-read.table("result_file_PCA.rel",head=F)
q2<-read.table("file1.clst",head=T)
autoplot(prcomp(q), data = q2,colour = 'CLUSTER')

Thank you very much for your help.

ggfortify r pca

1 answer

what's inside result_file_PCA.rel file and how was it generated?

The file was generated using this command:

plink --file pruned_filter_file --make-rel square --out result_file_PCA

the weirdest thing is that the first time i used R the result was great, a PCA plot just like it was intended. Then, in the following times the result was everytime an empty Rplots.pdf. I checked the result_file_PCA.rel and it's a perfectly normal distance matrix, the file is ok. It's weird.

I’ve had problems with saving some plots outside of package specific functions (ie ggsave). What I noticed was that it mainly occurred when trying to overwrite a file but not when creating a new file.

Can you see the output from autoplot? if so, you can save it as object some thing like this:

p=autoplot(prcomp(q), data = q2,colour = 'CLUSTER')
pdf("output.pdf")
print(p)
dev.off()

Since ggfortify is based on ggplot, you can also use ggsave to save a plot.

I followed your suggestion and it worked. Thank you very much.

Log in to answer this question.