2

我正在尝试绘制主要组件。我正在使用以下代码。我遇到的一个问题是变量的标签彼此太接近。我读到使用 ggrepel 解决了这个问题。

这是一个示例数据

EDIT1:进行更改以创建可重现的输出

set.seed(1)
dat <- data.frame(
  Diet = sample(1:2),
  Outcome1 = sample(1:10),
  Outcome2 = sample(11:20),
  Outcome3 = sample(21:30),
  Response1 = sample(31:40),
  Response2 = sample(41:50),
  Response3 = sample(51:60)
)

ir.pca <- prcomp(dat[,3:5], center = TRUE, scale. = TRUE) 

summary(ir.pca)

loadings <- ir.pca$rotation

scores <- ir.pca$x

correlations <- t(loadings)*ir.pca$sdev

plot(ir.pca, type = "l",main="")

ggbiplot(ir.pca, choices=c(1,2), obs.scale = 1, var.scale = 1)

dat2 <- as.data.frame(dat)
ggbiplot(ir.pca, choices=c(1,2), # creates a plot with ellipse
         groups=dat2[,1],
         obs.scale = 1, 
         var.scale = 1, 
         ellipse = TRUE)

我该怎么做才能在 ggplot 中绘制相同的图表?这样我就可以使用ggrepel了吗?

4

0 回答 0