3D pca中的”line”及其含义是什么?

huangapple go评论67阅读模式
英文:

What is the line in a 3D pca and its meaning?

问题

最近,我专注于3D PCA。我知道如何通过R中的不同包(如plotly、rgl等)生成3D PCA图。

但是我有一个关于下面图片的小问题:

我不知道如何在R中像图片中所示添加垂直线。

它只是用于定位PC1上的样本点吗?还是有其他特殊的含义?

这里有一个简单的示例数据和代码:
但我不确定是否通过这个包添加了垂直线。

library(rgl)
pc <- prcomp(~ . - Species, data = iris, scale = TRUE)

scores = as.data.frame(pc$x)
plot3d(scores[,1:3],
       
       main="ABC")

我希望有人能给我一些建议或解决方案。

提前感谢。

英文:

Recently, I focused on 3D PCA. And I know how to produce 3D PCA plots through different packages in R, such as plotly, rgl and so on.

But I have a small question from the picture below:

I don't know how to add vertical lines in R just as the picture showed.

And it is only used to locate sample points on PC1 ? Or other special meaning ?

Here is a simple example data and code:
But I am not sure vertical lines are added by this package.

library(rgl)
pc &lt;- prcomp(~ . - Species, data = iris, scale = TRUE)

scores = as.data.frame(pc$x)
plot3d(scores[,1:3],
       
       main=&quot;ABC&quot;)

I hope somebody could give me some advice or solutions.

Thanks in advance.

3D pca中的”line”及其含义是什么?

答案1

得分: 2

以下是翻译好的内容:

这不太美观,但要在rgl中重现类似的效果,您可以使用segments3d:

library(rgl)
pc <- prcomp(~ . - Species, data = iris, scale = TRUE)

scores = as.data.frame(pc$x)
plot3d(scores[,1:3],
  main="ABC")

lims <- apply(scores[,1:3], 2, range)

apply(scores[,1:3], 1, FUN = function(X){
  segments3d(
    x = rep(X[1], 2), 
    y = rep(X[2], 2),
    z = c(X[3], lims[1,3]))
})

您可能希望考虑使用persptrans3d以获得更多控制。

英文:

This is not pretty, but to reproduce something like this in rgl, you can used segments3d:

library(rgl)
pc &lt;- prcomp(~ . - Species, data = iris, scale = TRUE)

scores = as.data.frame(pc$x)
plot3d(scores[,1:3],
  main=&quot;ABC&quot;)

lims &lt;- apply(scores[,1:3], 2, range)

apply(scores[,1:3], 1, FUN = function(X){
  segments3d(
    x = rep(X[1], 2), 
    y = rep(X[2], 2),
    z = c(X[3], lims[1,3]))
})

3D pca中的”line”及其含义是什么?

You may want to look into using persp and trans3d for more control.

huangapple
  • 本文由 发表于 2023年6月26日 21:09:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76557013.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定