Browse code

hotfix pca_biplot

Gavin Rhys Lloyd authored on 19/02/2025 11:14:32
Showing 3 changed files

... ...
@@ -1,7 +1,7 @@
1 1
 Package: structToolbox
2 2
 Type: Package
3 3
 Title: Data processing & analysis tools for Metabolomics and other omics
4
-Version: 1.18.1
4
+Version: 1.18.2
5 5
 Authors@R: c(
6 6
     person(
7 7
         c("Gavin","Rhys"),
... ...
@@ -1,3 +1,6 @@
1
+Changes 1.18.2
2
++ fix pca_biplot
3
+
1 4
 Changes 1.81.1
2 5
 + fix missing interactions for ANOVA outputs
3 6
 
... ...
@@ -277,29 +277,10 @@ setMethod(f="chart_plot",
277 277
         P=output_value(dobj,'loadings')
278 278
         Ev=output_value(dobj,'eigenvalues')
279 279
         
280
-        # eigenvalues were square rooted when training PCA
281
-        Ev=Ev[,1]
282
-        Ev=Ev^2
283
-        
284
-        ## unscale the scores
285
-        #ev are the norms of scores
286
-        Ts=as.matrix(Ts) %*% diag(1/Ev) # these are normalised scores
287
-        
288
-        # scale scores and loadings by alpha
289
-        Ts=Ts %*% diag(Ev^(1-opt$scale_factor))
290
-        P=as.matrix(P) %*% diag(Ev^(opt$scale_factor))
291
-        
292
-        # additionally scale the loadings
293
-        sf=min(max(abs(Ts[,opt$components[1]]))/max(abs(P[,opt$components[1]])),
294
-            max(abs(Ts[,opt$components[2]]))/max(abs(P[,opt$components[2]])))
295
-        Ts=as.data.frame(Ts)
296
-        
297
-        rownames(Ts)=rownames(dobj$scores) # fix dimnames for SE object
298
-        colnames(Ts)=colnames(dobj$scores)
299
-        dobj$scores$data=as.data.frame(Ts) # nb object not returned, so only temporary scaling
280
+        sf = max(abs(Ts)) / max(abs(P)) * opt$scale_factor
300 281
         
301 282
         # plot
302
-        A=data.frame("x"=P[,opt$components[1]]*sf*0.8,"y"=P[,opt$components[2]]*sf*0.8)
283
+        A=data.frame("x"=P[,opt$components[1]]*sf,"y"=P[,opt$components[2]]*sf)
303 284
         C=pca_scores_plot(points_to_label=obj$points_to_label,xcol=obj$components[1],ycol=obj$components[2],factor_name=obj$factor_name)
304 285
         out=chart_plot(C,dobj)
305 286