1

Is there any way to remove the sample IDs from a ggbiplot and instead add dots which represent each sample? I am using the script below, but have more data in my PCA and the IDs are currently making everything look messy, and dots or circles would therefore be of preference.

A similar question was posted before, where the advice was to replace geom_text() with geom_point() in a ggplot2, but there is not code for geom text in this ggbiplot script.

Is there any way of doing this in a ggbiplot using this script?

library(ggbiplot)

library(datasets)

head(mtcars)

mtcars.pca <- prcomp(mtcars[,c(1:7,10,11)], center = TRUE,scale. = TRUE)

summary(mtcars.pca)

str(mtcars.pca)

ggbiplot(mtcars.pca)

ggbiplot(mtcars.pca, labels=rownames(mtcars))

mtcars.country <- c(rep("Japan", 3), rep("US",4), rep("Europe", 7),rep("US",3), "Europe", rep("Japan", 3), rep("US",4), rep("Europe", 3), "US", rep("Europe", 3))

ggbiplot(mtcars.pca,ellipse=TRUE,  labels=rownames(mtcars), groups=mtcars.country) 

ggbiplot(mtcars.pca,ellipse=TRUE,choices=c(3,4),   labels=rownames(mtcars), groups=mtcars.country) 

ggbiplot(mtcars.pca,ellipse=TRUE,obs.scale = 1, var.scale = 1,  labels=rownames(mtcars), groups=mtcars.country) 

ggbiplot(mtcars.pca,ellipse=TRUE,obs.scale = 1, var.scale = 1,var.axes=FALSE,   labels=rownames(mtcars), groups=mtcars.country) 

ggbiplot(mtcars.pca,ellipse=TRUE,obs.scale = 1, var.scale = 1,  labels=rownames(mtcars), groups=mtcars.country) +
  scale_colour_manual(name="Origin", values= c("forest green", "dark red", "navy blue"))+
  ggtitle("PCA of mtcars dataset")+
  theme_classic()+
  theme(legend.position = "bottom")

Malin
  • 11
  • 2

1 Answers1

0

By altering the last part of the current script a tad I was able to exclude the labels and add colours to the points. It now looks like this.

ggbiplot(mtcars.pca,ellipse=TRUE,obs.scale = 1, var.scale = 1, colours=mtcars.country, labels=NULL +
  scale_colour_manual(name="Origin", values= c("forest green", "dark red", "navy blue"))+
  ggtitle("PCA of mtcars dataset")+
  theme_classic()+
  theme(legend.position = "bottom")
Malin
  • 11
  • 2