繁体   English   中英

从 ggbiplot、R 中的 PCA plot 中删除样本 ID

[英]Removing sample IDs from PCA plot in ggbiplot, R

有什么方法可以从 ggbiplot 中删除样本 ID,而是添加代表每个样本的点? 我正在使用下面的脚本,但我的 PCA 中有更多数据,并且 ID 当前使一切看起来很混乱,因此点或圆圈将是首选。

之前发布了一个类似的问题,建议在 Z64B86077DA4139966627142D3C46164CBZ 中将 geom_text() 替换为 geom_point(),但此 ggbiplot 脚本中没有 geom 文本的代码。

有没有办法使用这个脚本在 ggbiplot 中做到这一点?

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")

通过稍微改变当前脚本的最后一部分,我能够排除标签并向点添加颜色。 现在看起来像这样。

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")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM