You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R中使用install_github函数?安装ggbiplot遇报错求助

解决ggbiplot安装报错及目标代码运行问题

报错原因分析

你遇到的Error in parse_repo_spec(repo) : Invalid git repo specification: 'ggbiplot'错误,核心问题有两个:

  1. 错误调用install.packages("install_github"):install_github是devtools包内置的函数,并非独立的R包,不需要用install.packages安装。
  2. install_github参数格式过时:新版devtools要求仓库地址以"用户名/仓库名"的单一字符串形式传入,而非分开传递仓库名和用户名两个参数。

正确安装步骤

执行以下代码完成ggbiplot的正确安装:

# 若未安装devtools,先执行此步骤
install.packages("devtools")

# 加载devtools包
library(devtools)

# 若因SSL验证问题无法安装,可临时关闭验证(注意:此操作存在安全风险)
library(httr)
set_config(config(ssl_verifypeer = 0L))

# 正确安装ggbiplot
install_github("vqv/ggbiplot")

验证安装并运行目标代码

安装完成后,直接运行你提供的目标代码即可生成PCA可视化图:

# Load data
data(iris)
log.ir <- log(iris[, 1:4])
ir.species <- iris[, 5]

#PCA
ir.pca <- prcomp(log.ir,
                 center = TRUE,
                 scale. = TRUE) 
#Plot
g <- ggbiplot(ir.pca, obs.scale = 1, var.scale = 1, 
              groups = ir.species, ellipse = TRUE, 
              circle = TRUE)
g <- g + scale_color_discrete(name = '')
g <- g + theme(legend.direction = 'horizontal', 
               legend.position = 'top')
print(g)

内容的提问来源于stack exchange,提问作者Rspacer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 02:05:19