【问题标题】:How can I reverse the axis in a biplot如何在双图中反转轴
【发布时间】:2019-04-24 02:45:21
【问题描述】:

当我绘制 PCA 和相应的双图时,轴并不总是在同一方向,就像这些图片中一样:

这些是我使用的函数:

(pc <- prcomp(dat5, center=T, retx=T, scale=T)); summary(pc)
plot(pc$x[,1:2], pch=""); text(pc$x[,1:2], cex=.5, labels=(row.names(dat5)), col=as.numeric(dat$ObCl))     
biplot(princomp(dat5, cor=T), cex=.5)

我怎样才能改变其中之一的轴方向,使它们相同?

【问题讨论】:

  • 你的第二个情节很清楚,但你是如何生成第一个情节的。 pc 是什么?
  • 可能是prcomp 的结果。顺便说一句,reproducible example 总是有帮助
  • 完全正确 :) 抱歉蜜蜂太短了。这是 prcomp 代码:
  • (pc
  • 感谢您的编辑,MrFlick!

标签: r plot axis pca biplot


【解决方案1】:

PC 的符号是任意的,您可以通过将一台或多台 PC 乘以 -1 来更改它/它们。请注意,这仅代表表示,具体取决于您所做的事情,例如,如果您使用$rotation,您可能还需要更改相应的列。以下是iris 的示例。希望这会有所帮助。

p <- prcomp(iris[, -5])
plot(p$x[, 1:2], asp=1, xlab="PC1", ylab="PC2")

plot(cbind(p$x[, 1], p$x[, 2]*-1), asp=1, xlab="PC1", ylab="PC2")

【讨论】:

  • 绘图(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2");
  • 文本(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2", cex= .5, 标签=(row.names(dat5)), col=as.numeric(dat$ObCl))
  • # 我只是不想去掉带有 pch="" 的符号,因为我想使用文本来代替...
  • 绘图(cbind(p$x[, 1], p$x[, 2]*-1), asp=1, xlab="PC1", ylab="PC2", pch=不适用);文本(cbind(p$x[, 1], p$x[, 2]*-1), 标签=1:150)。只需将 1:150 替换为您的标签,您也可以使用颜色。
  • 啊,pch=NA :) 再次感谢您 :)
猜你喜欢
  • 2013-08-01
  • 2019-11-03
  • 2014-08-21
  • 1970-01-01
  • 1970-01-01
  • 2022-07-07
  • 2021-02-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多