vegandevs / vegan

R package for community ecologists: popular ordination methods, ecological null models & diversity analysis
https://vegandevs.github.io/vegan/
GNU General Public License v2.0
449 stars 96 forks source link

calculating centroids for a two way combination #417

Closed aguilart closed 3 years ago

aguilart commented 3 years ago

Hello, just for visualization, I want to plot the centroids of a PCoA (or an NMDS) from a multivariate dataset that comes from two-factorial experiment desing. That is, I have lab based microbial community data (relative abundances) coming from an experiment following a two factorial design.

I plotted all the data using ggplot by extracting the coordinates of the first two axis using the scores function. But to simplify it, I would like to see only the centroids per treatment combination. Using envfit I get the centroids for each "main" factor:

en_pco <-envfit(spec.pco~Treatment, data= OTU_abundance6, permutations = 999, na.rm = TRUE)

en_pco$factors$centroids

                          Dim1         Dim2
TreatmentControl  0.0005378242 -0.002919174
TreatmentDrought -0.0005378242  0.002919174

But, I realize that these centroids are actually means of the first two axis:

temp_pco %>% group_by(Treatment) %>% summarise_at(c("Dim1","Dim2"),mean)

 Treatment      Dim1     Dim2
  <chr>         <dbl>    <dbl>
1 Control    0.000538 -0.00292
2 Drought   -0.000538  0.00292

This would mean that one could just calculate the mean per treatment combination on the two axis to get the centroids per group, right?

Sth like:

temp_pco %>% group_by(Treatment,Plant) %>% summarise_at(c("Dim1","Dim2"),mean)

jarioksa commented 3 years ago

Yes, for unweighted methods they are simple means (and for CA/CCA they are weighted means).

aguilart commented 3 years ago

thanks!