【问题标题】:Removing sample IDs from PCA plot in ggbiplot, R从 ggbiplot,R 中的 PCA 图中删除样本 ID
【发布时间】:2022-01-06 10:48:48
【问题描述】:

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

之前发布了一个类似的问题,建议在 ggplot2 中将 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")

【问题讨论】:

    标签: r ggplot2 pca ggbiplot


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-24
      • 1970-01-01
      • 2022-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多