Skip to content

Instantly share code, notes, and snippets.

@inventionate
Last active February 3, 2016 15:38
Show Gist options
  • Save inventionate/66eac8a644223809826f to your computer and use it in GitHub Desktop.
Save inventionate/66eac8a644223809826f to your computer and use it in GitHub Desktop.
Konzentrationsellipsen platten (GDA und ggplot2)
# Strukturierte Datenanalyse (grafische Umsetzung in ggplot2 2.0.0)
# Datensätze für die Ellipsen zusammenstellen
coord_ind <- data.frame(ergebnis_korrespondenzanalyse$ind$coord[, c(1:2)], geschlecht = ergebnis_korrespondenzanalyse$call$X[,7])
coord_quali <- coord_sup %>% group_by(geschlecht) %>% summarise_each(funs(mean))
# Korrespondenzanalyse plotten
fviz_mca_ind(ergebnis_korrespondenzanalyse, habillage = 7, addEllipses = FALSE, label = "none", pointsize = 0, col.ind = "black") + theme_minimal() +
theme( legend.position = "none") + geom_hline(yintercept = 0, color = "black", linetype="solid", size = 0.75) +
geom_vline(xintercept = 0, color = "black", linetype="solid", size = 0.75) +
# ALlgemeine Konzentrationsellipse hinzufügen
stat_ellipse(data = coord_ind, aes(x = Dim.1, y = Dim.2), geom ="polygon", level = 0.95, type = "norm", alpha = 0.1, colour = "black") +
stat_ellipse(data = coord_ind, aes(x = Dim.1, y = Dim.2), geom ="path", type = "norm", alpha = 1, colour = "black", linetype = "dashed", segments = 100) +
# Konzentrationsellipsen für die passiven Variablengruppen (i. d. F. "Geschlecht")
geom_point(data = coord_sup, aes(x = Dim.1, y = Dim.2, colour = geschlecht)) +
geom_point(data = coord_quali, aes(x = Dim.1, y = Dim.2, colour = geschlecht), shape = 18, size = 7) +
stat_ellipse(data = coord_ind, aes(x = Dim.1, y = Dim.2, fill = geschlecht), geom ="polygon", type = "norm", alpha = 0.15, segments = 100) +
stat_ellipse(data = coord_ind, aes(x = Dim.1, y = Dim.2, colour = geschlecht), geom ="path", type = "norm", alpha = 1, linetype = "solid", segments = 100) +
scale_colour_hue() + scale_fill_hue() + facet_wrap(~geschlecht)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment