`I want to change the color of just one variable, and leave the others in the colors they are in, in the multiple correspondence analysis. I have a data frame that I will specify below. I want the COURSES variable to be black and the others to be colored. And then create ellipses around the points that are close to each other, so that I can demonstrate it more clearly in the presentation. I just managed to build this script. How to go further?
I managed to generate a graph, but I want to make it more presentable. Being able to change colors of the variables,and I want create ellipses`
test2(COURSES,CLASSES,ARRANGEMENTS,QUANTITY_CHILD, REGIONS,COLOR_FAMILY,INCOME, EDUCATION,AGE,SEX,COST)
# SCRIPT:
ACM <- dudi.acm(test2 [,1:11],
scannf = FALSE)
# VIEW THE COORDINATE OF CATEGORIES
ACM$co
# VIEW THE PERCENTAGES OF THE CATEGORIES
ACM$cw
# amount of variance captured by each category, in a simple way
ACM$eig
# Variance from each dimension
perc_variance <- (ACM$eig / sum(ACM$eig)) * 100
# How many categories per variable
qty_categories <- apply( test2[,1:11], 2, function(x) nlevels(as.factor(x)) )
# Create the df with coordinates
df_ACM <- data.frame(ACM$co,
Variable = rep(names(qty_categories),
qty_categories) )
# Plotting the perceptual map
df_ACM %>%
rownames_to_column() %>%
rename(Category = 1) %>%
mutate(Category = gsub("COURSES.","", Category),
Category = gsub("ARRANGEMENTS.","", Category),
Category = gsub("COLOR_FAMILY.","", Category),
Category = gsub("COST.","", Category),
Category = gsub("SCHOOLING.","", Category),
Category = gsub("AGE.","", Category),
Category = gsub("QTCD.","", Category),
Category = gsub("REGIONS.","", Category),
Category = gsub("INCOME.","", Category),
Category = gsub("SEX.","", Category),
Category = gsub("CLASSES.","", Category)) %>%
ggplot(aes(x = Comp1, y = Comp2, label = Category, color = Variable)) +
geom_point() +
geom_text_repel() +
geom_vline(aes(xintercept = 0), linetype = "longdash", color = "grey48") +
geom_hline(aes(yintercept = 0), linetype = "longdash", color = "grey48") +
labs(x = paste("Dimensão 1:", paste0(round(perc_variance[1], 2), "%")),
y = paste("Dimensão 2:", paste0(round(perc_variance[2], 2), "%"))) +
theme_bw()
Lucas Dos Santos Jambeiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.