build_by_importance_node_legend <-
function (metric_data, metric_name, max_marker_size=8, min_marker_size=5) {
# (1) Get stats about important nodes
legend_data <- metric_data %>%
arrange(desc(metric_rate)) %>% # sort metric in descending order
filter(selected == 1) %>% # get only the important nodes
mutate(labels = paste(station, "(", metric_rate, "%" , ")")) %>% # create labels
select(node_color, labels) # get only labels and node colors
# (2) Add the stats about the rest if not all nodes have already been mapped
if (nrow(legend_data) < nrow(metric_data)) {
rest_percentage <-
sum((metric_data %>% filter(selected == 0))$metric_rate)
rest_label <- paste('Rest', '(', rest_percentage, '%', ')')
legend_data[nrow(legend_data) + 1, ] <- c('#000000', rest_label)
}
# (3) Add size for the markers
legend_data$marker_size <- seq(from=max_marker_size,
to=min_marker_size,
length.out = nrow(legend_data))
return(legend_data)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.