Skip to content

habillage stops working for one variable #177

@codonopsisczy

Description

@codonopsisczy

Hi,

I really love this package and have never had an issue until today. Due diligence: I have re-installed the package, restarted R, searched stack exchange, dummy coded a new variable, tried palette, tried subsetting so only the variable that won't habillage is included etc.

I ran prcomp on a dataframe and want to use fviz_pca_ind to see where the individuals land. I have 10 categorical variables that I can habillage by with no problem. When I try to habillage by "mulch" there is no color grouping. Mulch shows up as a factor with three levels, n values are missing. I don't know what to do.

#The data
NYbeet <- (see attached data

NYbeet <- NYbeet %>% 
  mutate_at(vars(year, crop, trt, system, till, tarp, mulch, block, plot), factor) %>% drop_na()

#the PCA
pcaNYbeet <- prcomp((NYbeet[,10:20]), scale = TRUE)

#Visualize the Eigenvalues 
fviz_eig(pcaNYbeet)

#Plot by variables
fviz_pca_var(pcaNYbeet, repel = TRUE)

summary(pcaNYbeet)
NYbeetvar <- get_pca_var(pcaNYbeet)
NYbeetvarred <- get_pca_var(pcaNYbeetred)

NYbeetvar$coord
NYbeetvar$cos2
NYbeetvar$contrib



NYbeetind <- get_pca_ind(pcaNYbeet)
NYbeetindred <- get_pca_ind(pcaNYbeetred)

NYbeetind$coord
NYbeetind$cos2
NYbeetind$contrib

#Plot by individuals, by habillage type. 

fviz_pca_ind(pcaNYbeet, repel = TRUE, label ="none", geom = "point", pointsize=3)

fviz_pca_ind(pcaNYbeet, repel = TRUE, label ="none", habillage = NYbeet$year, geom = "point", pointsize=3)

fviz_pca_ind(pcaNYbeet, repel = TRUE, label ="none", habillage = NYbeet$system, geom = "point", pointsize=3)

fviz_pca_ind(pcaNYbeet, repel = TRUE, label ="none", habillage = NYbeet$till, geom = "point", pointsize=3)

fviz_pca_ind(pcaNYbeet, repel = TRUE, label ="none", habillage = NYbeet$tarp, geom = "point", pointsize=3)

fviz_pca_ind(pcaNYbeet, repel = TRUE, label ="mulch", habillage = NYbeet$mulch, geom = "point", pointsize=3)

#Everything works except the last one

Book2.xlsx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions