Я могу создать желаемый график, извлекая координаты для отдельных точек и групповых частей из объекта MFA, созданного MFA (), res.mfa, и использую эти кусочки и ggplot2, чтобы сделать именно то, что я искал:
library("FactoMineR"); library("factoextra");library(wesanderson);library(ggplot2); library(ggpubr)
data(wine)
colnames(wine)
res.mfa <- MFA(wine, group = c(2, 5, 3, 10, 9, 2), type = c("n", "s", "s", "s", "s", "s"),name.group = c("origin","odor","visual", "odor.after.shaking", "taste","overall"), num.group.sup = c(1, 6),graph = FALSE)
row.names(res.mfa$ind$coord); row.names(wine)
Label <- wine[,1:2]
a <- merge(Label, res.mfa$ind$coord, by=0, all=TRUE)
row.names(a) <- a$Row.names
a <- a[,-c(1,3,6:8)]
a$Label <- as.factor(a$Label)
group.partials <- data.frame(res.mfa$quali.var$coord.partiel); group.partials <- group.partials[,1:2]
group.center <- data.frame((res.mfa$quali.var$coord)); group.center <- group.center[,1:2]
group.partials.and.center <- rbind(group.center, group.partials)
group.partials.and.center <- group.partials.and.center[ order(row.names(group.partials.and.center)), ]
rm(group.partials, group.center)
row.names(group.partials.and.center)
Labelrows <- c(1:10, 31:35) # The rows for groups I want to plot with ellipses and partials.
group.partials.and.center <- group.partials.and.center[Labelrows,]
pal<- wes_palette(3, name = "Zissou1", type = "continuous")
ggplot(a, aes(Dim.1, Dim.2, group=Label)) +
geom_point(size=5, aes(color=Label))+
scale_color_manual(values=wes_palette(3, name = "Zissou1", type = "continuous")) +
stat_conf_ellipse(aes(color = Label), bary = TRUE, size=1.2) +
theme(legend.position="top", legend.text=element_text(size=12),
legend.title = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
line = element_blank(),
axis.line= element_blank()) +
#Plot partials for each desired "Label" group
# Saumur, group.partials.and.center[11:15,]
# To plot the partials for the other groups,
#Bourgueuil (group.partials.and.center[1:5,])
#Chinon ((group.partials.and.center[6:10,])
# Repeat the code below for each, adjusting for appropriate rows:
geom_point(aes(x=group.partials.and.center[11,1],y=group.partials.and.center[11,2]))+ # Centers of ellipses
geom_segment(aes(x=group.partials.and.center[11,1],y=group.partials.and.center[11,2], # Center of ellipses
xend=group.partials.and.center[12,1],yend=group.partials.and.center[12,2]),
arrow=arrow(length = unit(0.2,"cm"),angle=90), lineend = "butt", linetype=1)+
geom_segment(aes(x=group.partials.and.center[11,1],y=group.partials.and.center[11,2], # Center of ellipses
xend=group.partials.and.center[13,1],yend=group.partials.and.center[13,2]),
arrow=arrow(length = unit(0.2,"cm"),angle=90),lineend = "butt", linetype=2)+
geom_segment(aes(x=group.partials.and.center[11,1],y=group.partials.and.center[11,2], # Center of ellipses
xend=group.partials.and.center[14,1],yend=group.partials.and.center[14,2]),
arrow=arrow(length = unit(0.2,"cm"),angle=90), lineend = "butt", linetype=3)+
geom_segment(aes(x=group.partials.and.center[11,1],y=group.partials.and.center[11,2], # Center of ellipses
xend=group.partials.and.center[15,1],yend=group.partials.and.center[15,2]),
arrow=arrow(length = unit(0.2,"cm"),angle=90), lineend = "butt", linetype=4, linejoin = "round")