2

I'm a very new coder looking to change the shapes of my PCA Biplot. My PCA Biplot code is as follows:

group <- c(rep("SHIME 1_Trt1", times=8), rep('SHIME 1_Trt2', times=6),
rep("SHIME 2_Trt1", times=8), rep('SHIME 2_Trt2', times=6),
rep("SHIME 3_Trt1", times=8), rep('SHIME 3_Trt2', times=6)) 

clusters <- c(rep("SCFA", times=3), rep("Organic acid", times=3), 
rep("Alcohols", times=3), rep('AA', times=2), rep('Ketone', times=1), rep('Lipid', times=1))

j_scale <- prcomp(j, center=TRUE, scale=TRUE)

fviz_pca_biplot(j_scale, repel=TRUE, pointsize=4, pointshape=21, col.var=factor(clusters),
 arrowsize=0.6, labelsize=4, 
palette=c("#00AFBB", "#00AFBB", "#E7B800", "#E7B800", "#FC4E07", "#FC4E07", "#FC4E08"),
geom='point', fill.ind=group, legend.title=list(fill='System',color='Categories')) +
ggpubr::color_palette("lancet") 

The colors are arranged as I'd like it, but i'd like the shapes to be different between Trts. Example: shime1 trt 1 = blue circle, shime 1 trt 2 = blue sq, shime 2 trt 1 = green circle, etc. See picture below for current biplot.

I've tried:

scale_shape_manual(values=c()), habillage=group

doesn't give me the same output as fill.ind and clashes with col.var= , geom.ind/var, and shape.ind

Changing pointshape=c() doesn't seem to work either

And even a modified code:

fviz_pca_biplot(j_scale, repel=TRUE, pointsize=4, pointshape=21, col.ind=shimeb_pca$Type,
col.var='black',  arrowsize=0.6, labelsize=4, 
palette=c("#00AFBB", "#00AFBB", "#E7B800", "#E7B800", "#FC4E07", "#FC4E07", "#FC4E08"), 
geom='point', legend.title=list(fill='System')) + theme_minimal() + 
scale_shape_manual(values=c(5, 20, 21, 20, 21, 20))
#This looks worse than the original code

Data excerpt prior to prcomp(j, center=TRUE, scale=TRUE):

         Acetate Propionate  Butyrate   Lactate  Formate Succinate   Ethanol Methanol
S1_0    40.09358  10.726725 0.7180000 0.6104750 1.901075 0.5284000 10.730900 1.163525
S1_1    40.05890  10.962025 0.6841500 0.7253000 1.958825 0.7286250 11.013750 1.217125
S1_1.5  44.27740  13.020812 0.8308875 0.4131125 1.355225 0.0539250 10.897100 1.267700
S1_2    43.87610  11.580800 0.6531500 0.7476500 2.461150 0.7961250  9.628950 1.338500
S1_3    45.70235  12.458150 0.7131750 0.4026250 2.059375 0.5043250 20.098575 1.426900
S1_5    45.15580  12.711575 0.7775750 0.1914750 0.864700 0.0535750 10.404050 1.357200
S1_7    44.11000  12.885625 0.7210250 0.3525500 2.534225 0.0616750  7.744150 1.431675
S1_9    47.27562  12.739375 0.6837000 0.4053000 2.804775 0.0570500 13.701000 1.630200

Picture of updated biplot

Any help is appreciated. Thanks in advance.

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
Coldgrad
  • 59
  • 7

1 Answers1

0

Try fviz_pca_biplot(j_scale, geom.ind = 'point', repel = TRUE, pointsize = 4, habillage = group, arrowsize = 0.6, labelsize = 4, legend.title = list(fill = 'System'))

Good Job.

Wilson Souza
  • 830
  • 4
  • 12
  • I received this error based on your edited script: `Error: Aesthetics must be either length 1 or the same as the data (42): shape Run rlang::last_error() to see where the error occurred. In addition: Warning messages: 1: In if (shape %in% colnames(data)) { : the condition has length > 1 and only the first element will be used 2: In if (shape %in% colnames(data)) { : the condition has length > 1 and only the first element will be used.` It seems that the argument `pointshape=` isn't in line with the `fill.ind= argument? – Coldgrad Apr 23 '21 at 22:45
  • Thanks for the update again. Unfortunately habillage isn't working for me as I have tried it before and it clashes with `col.var=factor(clusters)` which are the categories of my arrows. I've updated my code in my OP. – Coldgrad Apr 24 '21 at 00:04
  • Could you add the data used for PCA? Not the part of PCA result. If necessary for preserve your data, you can change values. – Wilson Souza Apr 24 '21 at 00:19
  • 1
    Added to the OP. Thanks! – Coldgrad Apr 24 '21 at 00:20
  • See if this posts solve your question: 1) https://stackoverflow.com/questions/46934303/pca-change-colours-of-clusters 2) https://stackoverflow.com/questions/50449437/customization-of-pointshape-within-function-fviz-pca-from-factoextra-package 3) https://github.com/kassambara/factoextra/issues/42 Maybe the post of github is more adequate to solve it. – Wilson Souza Apr 24 '21 at 00:37
  • Thanks for pointing those out. I've tried those to the best of my coding knowledge prior to making this post, but no luck or i'm not inputting them correctly. In particular the 2nd link also used `habillage=` that again does not work for my plot (as far as i can tell). Indeed the github link is quite informative, but i couldn't discern or see that the posts resolved my inquiry. – Coldgrad Apr 24 '21 at 00:45