NovembreLab / PCAviz

An R package to help in plotting PCA results nicely.
http://jnpopgen.org/PCAviz
GNU General Public License v3.0
13 stars 5 forks source link

Issues with labels on PCA plots #5

Open sophiekj opened 3 years ago

sophiekj commented 3 years ago

We are having problems with not being able to remove labels from the dots on the PCA plot.

I figured out how to at least shorten the labels, so it doesn’t look quite as bad, but I followed the PCAviz program 'help' manual instructions for removing the labels on the plot and it didn’t work. For some reason, adding the shortened labels works but removing them completely doesn’t.

According to the PCAviz manual instructions, it seems like we are just supposed to add in

draw.points = TRUE, label = NULL

to the

plot1 <- plot(SGDP, coords = paste0(“PC”, c(1, 2)), color = “popID”, draw.points = TRUE, label = NULL, geom.point.summary.params = geom.point.summary.params, scale.pc.axes = 0.6)

but it still just draws the full-length labels anyway. However, our code does work for shortened labels, just not getting rid of them altogether (see plot and entire .R code attached):

plot1 <- plot(SGDP, coords = paste0(“PC”, c(1, 2)), color = “popID”, draw.points = TRUE, label = “popID.abbrv”, geom.point.summary.params = geom.point.summary.params, scale.pc.axes = 0.6)

Any advice or code you can provide would we appreciated!

PCA 1 and 2 (Without Mbuti)

Here is our entire .R code:

install.packages("devtools")
devtools::install_github("NovembreLab/PCAviz",build_vignettes = TRUE)
library(PCAviz)
library(cowplot)
prefix <- "Simons.LDprune.out.pca"
nPCs <- 10

PCA <- read.table(paste(prefix, ".evec", sep = ""))
names(PCA) <- c("ID", paste("PC", (1:nPCs), sep = "") , "case.control")
PCA <- PCA[, 1:(nPCs+1)]
eig.val <- sqrt(unlist(read.table(paste(prefix, ".eval", sep = "")))[1:nPCs])
sum.eig <- sum(unlist(read.table(paste(prefix, ".eval", sep = "")))) 

snpeigs <- read.table(paste(prefix, ".snpeigs", sep = ""))
names(snpeigs) <- c("ID", "chr", "pos", 
                    paste("PC", (1:nPCs), sep = ""))
snpeigs$chr <- factor(snpeigs$chr)
rownames(snpeigs) <- snpeigs$ID
snpeigs <- snpeigs[, -1]

clst <- read.table("sampleandpopID_recode_NoMbuti.txt")
PCA <- as.data.frame(PCA)
PCA <- cbind(PCA, clst)
names(PCA)[ncol(PCA)] <- "popID"

SGDP <- pcaviz(dat = PCA, sdev = eig.val, var = sum.eig, rotation = snpeigs)
SGDP <- pcaviz_abbreviate_var(SGDP, "popID")

geom.point.summary.params <- list(shape = 16, stroke = 1, size = 5, alpha = 2, show.legend = F)
plot1 <- plot(SGDP, coords = paste0("PC", c(1, 2)), color = "popID", draw.points = TRUE, label = "popID.abbrv", geom.point.summary.params = geom.point.summary.params, scale.pc.axes = 0.6)

plot_grid(plot1)
pcarbo commented 3 years ago

@sophiekj It might be helpful to play around with these settings in the vignette. But I think what you want is something like this?

plot(iris,draw.points = TRUE,label = NULL,group.summary.labels = FALSE)