我有一个3D数据集( x,y,z坐标系),我已经在其上执行了PCA。我知道如何转换x,y,z数据以适应 PC1,PC2,PC3坐标系。但我想要的是在3D中将PC作为箭头绘制在 x,y,z坐标系上。
可重复数据:
library(rgl)
# read in data
data <- "x,y,z
104.470811919473,183.114702195258,12.7965677375691
103.883125175372,182.247375254372,12.8254943022833
104.449660085882,182.030561389885,12.8570720582426
105.180677421292,181.198801718839,12.8892530663987
107.80347161674,181.750770664165,12.3132109076902
106.510738329891,181.128870038149,12.7607172217969
107.395693480091,180.189211048631,12.1747046297813
107.475586782374,179.912224611249,12.8116157807916
107.215377340716,179.851028419945,12.7996617986497
106.492445290536,178.8750726955,12.8143339580613
106.02079729018,178.050557151059,12.7927918876051
105.940400054321,178.770806829626,12.8433344014522
106.966251136342,178.066703469875,12.8141731612946
106.55468234403,177.980800771319,12.3621410954583
105.950087539812,177.103145672738,12.1268413721531
104.213500127469,175.990037493638,12.1393980259327
106.501596858226,175.942082601673,12.0926070481083
107.750092619737,175.91847925273,12.2634369356027
107.391919253368,176.106162025913,12.1278854351213
108.135585465177,176.877859717427,12.1730353938959
109.455914423365,176.127624198463,12.8152345093824
109.239049856558,176.810085143556,12.7852759649393
109.512806112062,176.155208439023,12.3594455064334
109.208054934825,176.166383823346,12.0920754777309
108.185960658415,176.745948875769,12.8276628398591
109.295845466844,177.059177273982,12.8052598192756
109.191367554774,176.963840876036,12.0996879943814
109.372963078173,177.121528577422,12.1220328744238
110.098893635956,177.813513543068,12.8020438281896
110.381514646031,177.932238610464,12.1057424026678
109.329274183893,177.177155538408,12.1180545742678
109.348554906875,176.904507294421,12.1150736238504
108.151137556632,176.810920742201,12.1919472442841
109.275705497364,176.107627547166,12.1742023785419
109.506984983346,175.666303833657,12.2615995418739
109.17491026639,175.963528950806,12.1500621008826
109.211790657476,175.948369805023,12.1854664995505
109.073239601564,175.090929840985,12.2179008596746
110.105236016665,175.797523101787,12.7737084475498
110.400485121287,175.132936795876,12.129029502301
110.015009938162,175.235873650149,12.2129273114418
109.428358045527,174.844891089569,12.8423222585074
109.644487859159,175.276625489979,12.2793426985123
110.030575756877,175.966560940786,12.0842336826992
109.840686535536,175.938378391017,12.1011763639133
110.310571223539,176.076407954977,12.1604144035873
109.842679461167,176.195286472885,12.7046340834545
109.939286444355,176.836557651852,12.2366423702851
109.705939279377,176.315311985728,12.3088184482404
110.132818542908,177.114211834311,12.7917864141992
110.355388253279,176.926010839311,12.8305725248717
109.920305361809,176.071334146044,12.1851910648377
109.28400688079,176.071065060099,12.1551139196441
109.447659542616,176.001910128206,12.1405153172147"
df <- as.matrix(read.table(text=data, header = TRUE, sep=","))
# get pca results
pca <- princomp(df, cor=TRUE, scores=TRUE)
# plot original data
plot3d(x = df[,1], y = df[,2], z = df[,3], type = 'p', xlab = 'x', ylab = 'y', zlab = 'z', add=TRUE, col='red', cex.min=10, alpha=1)
decorate3d(axes=TRUE, add=TRUE)
# ** question: how do I add the PC's as arrows on this plot **