1

我正在尝试记录一些地球化学数据的转换,以便在 ggfortify 中执行 PCA。当我的数据框在日志转换后更改为值时,我收到以下错误。我需要把它转换回来。

    Error: `data` must be a data frame, or other object coercible by 
`fortify()`, not a numeric vector

我尝试使用以下代码解决它,但我仍然遇到问题。

    library(ggfortify)


LutregalaITRAXPCA<-read.csv("LutregalaITRAXPCA.csv",header=TRUE) #read 
in csv
log_features<-LutregalaITRAXPCA
log_features<-log(log_features) #log transform data
log_features <- unlist(log_features)
log_features[is.infinite(log_features)] <- -99999

df<-log_features
pca_res <- prcomp(df, scale. = TRUE)
autoplot(pca_res, data = df)




dput(head(log_features))
structure(list(Al = c(3.71357206670431, 4.48863636973214, 4.51085950651685, 
4.69134788222914, 4.56434819146784, 4.84418708645859), Si = 
c(3.66356164612965, 
4.47733681447821, 4.79579054559674, 4.79579054559674, 4.49980967033027, 
4.78749174278205), Cl = c(8.2495751500002, 8.72095002893026, 
9.12249228140299, 9.24792513230345, 9.42939557738179, 9.59865932124938
), Ca = c(7.35244110024358, 7.86326672400957, 8.21229713822977, 
8.2776661608515, 8.42376124662369, 8.52337405049132), Ti = 
c(4.71849887129509, 
5.6937321388027, 6.08904487544685, 5.92958914338989, 6.12905021006055, 
6.8330317327862), Mn = c(4.46590811865458, 5.84932477994686, 
5.71373280550937, 5.44673737166631, 5.33271879326537, 5.52146091786225
), Fe = c(10.0488857552255, 11.1511518304865, 11.8755457005861, 
12.1932457312753, 11.8706418664038, 11.5001947724914), Cu = 
c(5.62762111369064, 
5.73657229747919, 6.04737217904628, 6.06842558824411, 6.49978704065585, 
6.74993119378857), Zn = c(5.97888576490112, 5.89989735358249, 
5.67332326717149, 5.39362754635236, 5.76205138278018, 6.22059017009974
), Br = c(8.97853441008332, 9.46459491831544, 9.70430463866676, 
9.68040649926887, 9.72740648333163, 9.81765729593094), Rb = 
c(6.48463523563525, 
6.30627528694802, 4.02535169073515, 5.75574221358691, 4.23410650459726, 
6.02586597382531), Zr = c(-Inf, -Inf, -Inf, -Inf, -Inf, 4.30406509320417
), IncCoh = c(1.86745227902955, 1.89135537792017, 1.88204074800696, 
1.88562596044563, 1.89161767138497, 1.92164071294886)), row.names = c(NA, 
6L), class = "data.frame")`
4

0 回答 0