英文:
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 <- prcomp(~ . - Species, data = iris, scale = TRUE)
scores = as.data.frame(pc$x)
plot3d(scores[,1:3],
main="ABC")
I hope somebody could give me some advice or solutions.
Thanks in advance.
答案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]))
})
您可能希望考虑使用persp
和trans3d
以获得更多控制。
英文:
This is not pretty, but to reproduce something like this in rgl, you can used 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]))
})
You may want to look into using persp
and trans3d
for more control.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论