簡體   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