【问题标题】:Why is my princomp plot empty despite returning no errors?尽管没有返回错误,为什么我的 princomp 情节为空?
【发布时间】:2019-02-13 10:30:18
【问题描述】:

Princomp 已用于汇总大型数据集,汇总、screeplot 和加载都是功能性的,并且所有代码都是从早期的 pca 中重复的。绘图的代码也非常相似,运行时不会返回错误,但绘图完全是空的。

这最初是在原始代码中发生的,但问题似乎通过再次运行 princomp 和 summary 解决了,这次这个解决方案没有奏效。

Plot_chars.abio.pca <-princomp(Plot_chars_standardised[,4:12]) 
summary(Plot_chars.abio.pca)

Plot_chars.abio.pca$loadings

screeplot(Plot_chars.abio.pca, type="lines")


Plot_chars.abio.pca.var <- Plot_chars.all.pca$sdev^2
Plot_chars.abio.pca.var[1:5]

plot(Plot_chars.abio.pca$x[,1], Plot_chars.abio.pca$x[,2],
bty = "n",
pch = Plot_chars$DomSpec -20,
cex =0.5,
col= Plot_chars$DomSpec -10, 
xlim = c(-2,6),
ylim = c(-2,6),
xlab = "PCA1",
ylab = "PCA2")

我期待绘制 PC1 和 PC2 点,但没有出现

【问题讨论】:

    标签: r plot pca


    【解决方案1】:

    princomp 的结果不包含名为 x 的列。对于分数图,PC1 使用Plot_chars.abio.pca$scores[, 1]Plot_chars.abio.pca$scores[, 2]。对于载荷图,使用Plot_chars.abio.pca$loadings[, 1] 表示 PC1 中的载荷,使用Plot_chars.abio.pca$loadings[, 2] 表示 PC2 中的载荷。

    你的例子:

    plot(Plot_chars.abio.pca$scores[,1], Plot_chars.abio.pca$scores[,2],
    bty = "n",
    pch = Plot_chars$DomSpec -20,
    cex =0.5,
    col= Plot_chars$DomSpec -10, 
    xlim = c(-2,6),
    ylim = c(-2,6),
    xlab = "PCA1",
    ylab = "PCA2")
    

    【讨论】:

    • 非常感谢!我正在遵循一些课堂说明,这些说明告诉我要包括 x。效果很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 2021-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多