【问题标题】:How to change loading labels of biplot in r?如何在 r 中更改 biplot 的加载标签?
【发布时间】:2020-06-18 05:31:50
【问题描述】:

我正在努力更改双标图的加载标签。我使用 prcomp 函数来运行 PCA 和 ggbiplot。我尝试使用loading.label.label = c("a","b","c","d") 更改它,但没有成功。我在下面附上了我的代码和绘图。

k <- kmeans(comp,2)

TW$Group <- factor(k$cluster)

pca2 <- prcomp(TW[,c(7,11,18,19)], center = TRUE, scale. = TRUE)

summary(pca2)

pca2

cc <- c("a","b","c","d")

library(ggbiplot)

p <- ggbiplot(pca2, group = TW$Group, ellipse = TRUE,loadings.label.repel = TRUE) +
  ggrepel::geom_text_repel(aes(colour = TW$Group, label = paste(TW$P,TW$Box)), size = 2.5)+ 
  theme_minimal() +
  xlim(-2.5,2.5) + ylim(-2.5,3.5) + theme(legend.position = c(0.9, 0.9))

plot(p)

【问题讨论】:

    标签: r label pca ggbiplot prcomp


    【解决方案1】:

    不确定您是否可以使用 ggbiplot 函数执行此操作。一种解决方法是更改​​ pca 对象中的名称,如下所示:

    library(ggbiplot)
    data(wine)
    wine.pca <- prcomp(wine, scale. = TRUE)
    
    rownames(wine.pca$rotation) <- rep("my_names", length(wine.pca$center))
    print(ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, groups = wine.class, ellipse = TRUE, circle = TRUE))
    

    【讨论】:

      猜你喜欢
      • 2016-09-26
      • 2021-02-05
      • 2018-05-19
      • 1970-01-01
      • 2016-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-20
      相关资源
      最近更新 更多