更改自动绘图 PCA 中显示的方差比例的小数

发布于 2025-01-13 13:19:35 字数 286 浏览 4 评论 0原文

我想使用 prcomp()autoplot() 更改 PCA 图轴中显示的方差比例的小数位数>。默认情况下,它设置为 2 位小数(92.46%、5.31%),但我想将它们四舍五入到 1 位小数(92.5%、5.3%)。

库(ggfortify)
df <- 虹膜[1:4]
pca <- prcomp(df)
自动绘图(PCA)

谢谢你!

I would like to change the number of decimals for the Proportion of Variance displayed in the axes of a PCA plot using prcomp() and autoplot(). By default it's set to 2 decimals places (92.46%, 5.31%) but I'd like to round them to 1 decimal place (92.5%, 5.3%).

library(ggfortify)
df <- iris[1:4]
pca <- prcomp(df)
autoplot(pca)

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥抱没勇气 2025-01-20 13:19:35

首先,使用以下命令禁用显示的默认方差百分比:

autoplot(pca, variance_percentage = FALSE)

然后使用以下命令添加您想要的标签:

autoplot(pca, variance_percentage = FALSE) +
  xlab("PC1 (%)")

First, disable the default variance percentage displayed by using:

autoplot(pca, variance_percentage = FALSE)

Then add the labels you want using:

autoplot(pca, variance_percentage = FALSE) +
  xlab("PC1 (%)")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文