fawda123 / ggord

a take on ordination plots using ggplot2
https://fawda123.github.io/ggord/
62 stars 20 forks source link

Small things to fix... #2

Closed fawda123 closed 9 years ago

fawda123 commented 9 years ago

1.

library(ade4)
ord <- dudi.pca(iris[, 1:4], scannf = FALSE, nf = 2, center=TRUE, scale=TRUE)
ggord(ord, iris$Species) # TO DO: something wrong here with explained variance and scaling (different than prcomp, PCA and princomp)

# this gives the correct result :
library("devtools")
install_github("kassambara/factoextra")
library("factoextra")
ord <- dudi.pca(iris[, 1:4], scannf = FALSE, nf = 2, center=TRUE, scale=TRUE)
fviz_pca_biplot(ord,  # gives the correct result
                habillage = iris$Species, addEllipses = TRUE,
                col.var = "red", alpha.var ="cos2",
                label = "var") 
# see factoextra/R/get_pca.R
  1. for dudi.coa
# dudi.coa
library(ade4)
ord <- dudi.coa(iris[, 1:4], scannf = FALSE, nf = 4)
ggord(ord, iris$Species) # TO DO: scaling correct but %s on axes not correct
fviz_ca_biplot(ord,  # correct solution
               habillage = iris$Species, addEllipses = TRUE,
               col.var = "red", label = "var")
# see factoextra/R/get_ca.R

3.

# ca
library(ca)
ord <- ca(iris[, 1:4])
ggord(ord, iris$Species) # TO DO: scaling not correct, %s on axes correct
fviz_ca_biplot(ord,  # correct solution
               habillage = iris$Species, addEllipses = TRUE,
               col.var = "red", label = "var") 
# see factoextra/R/get_ca.R

4.

# acm
library(ade4)
ord <- dudi.acm(tea[, -1], scannf = FALSE)
ggord(ord, tea$Tea) # TO DO: similar to MCA, but %s on axes not correct
fviz_mca_biplot(ord,  # correct solution
                habillage = tea$Tea, addEllipses = TRUE,
                col.var = "red", label = "var")
# see factoextra/R/get_mca.R

5.

# mca
library(MASS)
ord <- mca(tea[, -1])
ggord(ord, tea$Tea) # TO DO: scaled differently as MCA and %s on axes not correct, mistake here?
# see factoextra/R/get_mca.R
fawda123 commented 9 years ago

Done - everything noted above has been corrected except for the scaling on item 5. I'm not sure the scaling is an issue because the plot method for mca produces the same scaling as a ggord plot.

library(MASS)
library(ggord)
data(tea, package = 'FactoMineR')
tea <- tea[, c('Tea', 'sugar', 'price', 'age_Q', 'sex')]

ord <- mca(tea[, -1])

plot(ord)
ggord(ord, tea$Tea) 

Also note that the explained variance of each axis is not the same as the other multiple correspondence analyses but they are identical to those returned with the object. Again, a MASS issue maybe.