Created
March 12, 2017 20:24
-
-
Save tvladeck/d999ede030a077a194b81c26eebad65b to your computer and use it in GitHub Desktop.
Method for producing table of clustering results based on SOMbrero output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
korresp_som <- trainSOM(a, scaling = "chi2", type = "korresp", dimension = c(2,2)) | |
row_num <- korresp_som$parameters$the.grid$dim[[1]] | |
col_num <- korresp_som$parameters$the.grid$dim[[2]] | |
korresp_clusters <- | |
korresp_som$clustering %>% | |
as.data.frame %>% | |
set_colnames(c("cluster")) %>% | |
mutate(entity = rownames(.)) %>% | |
group_by(cluster) %>% | |
mutate(row = (cluster - 1) %% row_num) %>% | |
mutate(column = (cluster - 1) %/% col_num) %>% | |
mutate(type = ifelse(entity %in% brand_list$category, "brand", "occasion")) | |
korresp_clusters %>% | |
ggplot(aes(x = 1, y = 1, label = str_wrap(entity, 20), fill = type)) + | |
geom_label_repel(segment.size = 0, family = "Consolas", size = 2) + | |
facet_grid(row ~ column) + | |
theme(text = element_text(family = "Consolas"), | |
panel.grid = element_blank(), | |
strip.text = element_blank(), | |
strip.background = element_blank(), | |
legend.position = "none") + | |
scale_x_continuous(name = "", breaks = NULL) + | |
scale_y_continuous(name = "", breaks = NULL) + | |
scale_fill_brewer(type = "seq", palette = 1, name = "") + | |
labs(title = cluster_name(cluster_idx), | |
subtitle = "Category / Occasion Grouping", | |
caption = "Clustering based on self-organized map of association table") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment