@@ -112,7 +112,7 @@ robyn_clusters <- function(input, all_media = NULL, k = "auto", limit = 1,
112112 if (export ) {
113113 fwrite(output $ data , file = paste0(path , " pareto_clusters.csv" ))
114114 ggsave(paste0(path , " pareto_clusters_wss.png" ), plot = output $ wss , dpi = 500 , width = 5 , height = 4 )
115- ggsave(paste0(path , " pareto_clusters_corr.png" ), plot = output $ corrs , dpi = 500 , width = 7 , height = 5 )
115+ # ggsave(paste0(path, "pareto_clusters_corr.png"), plot = output$corrs, dpi = 500, width = 7, height = 5)
116116 db <- wrap_plots(output $ plot_models_rois , output $ plot_models_errors )
117117 ggsave(paste0(path , " pareto_clusters_detail.png" ), plot = db , dpi = 600 , width = 12 , height = 9 )
118118 }
@@ -121,6 +121,28 @@ robyn_clusters <- function(input, all_media = NULL, k = "auto", limit = 1,
121121
122122}
123123
124+ # # Mean Media ROI by Cluster
125+ # df %>%
126+ # mutate(cluster = sprintf("Cluster %s", cls$df$cluster)) %>%
127+ # select(-.data$mape, -.data$decomp.rssd, -.data$nrmse, -.data$solID) %>%
128+ # group_by(.data$cluster) %>%
129+ # summarize_all(list(mean)) %>%
130+ # tidyr::pivot_longer(-one_of("cluster"), names_to = "media", values_to = "meanROI") %>%
131+ # ggplot(aes(y = reorder(.data$media, .data$meanROI), x = .data$meanROI)) +
132+ # facet_grid(.data$cluster~.) +
133+ # geom_col() + theme_lares() +
134+ # labs(title = "Mean Media ROI by Cluster",
135+ # x = "(Un-normalized) mean ROI within clsuter", y = NULL)
136+ # df %>%
137+ # mutate(cluster = sprintf("Cluster %s", cls$df$cluster)) %>%
138+ # select(-.data$solID, -.data$mape, -.data$decomp.rssd, -.data$nrmse) %>%
139+ # tidyr::pivot_longer(-one_of("cluster"), names_to = "media", values_to = "roi") %>%
140+ # ggplot(aes(y = reorder(.data$media, .data$roi), x = .data$roi)) +
141+ # facet_grid(.data$cluster~.) +
142+ # geom_boxplot() + theme_lares() +
143+ # labs(title = "Media ROI by Cluster",
144+ # x = "(Un-normalized) ROI", y = NULL)
145+
124146# ROIs data.frame for clustering (from xDecompAgg or pareto_aggregated.csv)
125147.prepare_roi <- function (x , all_media ) {
126148 check_opts(all_media , unique(x $ rn ))
@@ -171,7 +193,7 @@ robyn_clusters <- function(input, all_media = NULL, k = "auto", limit = 1,
171193 balance <- balance / sum(balance )
172194 left_join(df , select(top_sols , 1 : 3 ), " solID" ) %> %
173195 mutate(
174- alpha = ifelse(is.na(.data $ cluster ), 0.5 , 1 ),
196+ alpha = ifelse(is.na(.data $ cluster ), 0.6 , 1 ),
175197 label = ifelse(! is.na(.data $ cluster ), sprintf(
176198 " [%s.%s]" , .data $ cluster , .data $ rank
177199 ), NA )
0 commit comments