ox-it / OxfordIDN_htmlwidgets

Interactive visualisation templates with htmlwidgets and R
http://ox-it.github.io/OxfordIDN_htmlwidgets/
MIT License
3 stars 6 forks source link

charts/barchart: move to side-effects rather than modifying data when ordering #17

Closed charliejhadley closed 7 years ago

charliejhadley commented 7 years ago

Currently using

aggregate_mean <- aggregate_mean[order(aggregate_mean$Desktop.Items),]
highchart() %>%
  hc_chart(type = "bar") %>%
  hc_xAxis(categories = aggregate_mean[,selected_dimension]) %>%
  hc_add_series(name = format_label(selected_dimension), data = rev(aggregate_mean[,measure_column])) %>%
  hc_yAxis(title = list(text = "Mean Number of Desktop Items")) %>%
  hc_title(text = paste0("Mean number of desktop items aggregated by ",format_label(selected_dimension)))

Should not modify the data itself and instead:

aggregate_mean_sorted <-
  aggregate_mean[order(aggregate_mean$Desktop.Items, decreasing = TRUE), ]
highchart() %>%
  hc_chart(type = "bar") %>%
  hc_xAxis(categories = aggregate_mean_sorted[, selected_dimension]) %>%
  hc_add_series(name = format_label(selected_dimension), data = aggregate_mean_sorted) %>%
  hc_yAxis(title = list(text = "Mean Number of Desktop Items")) %>%
  hc_title(text = paste0(
    "Mean number of desktop items aggregated by ",
    format_label(selected_dimension)
  ))

Note that this change may need to be rolled through the rest of the document.

charliejhadley commented 7 years ago

Fixed in https://github.com/ox-it/OxfordIDN_htmlwidgets/commit/8af201f8437482afb6c5b87b27c8ba9e12e0e6fd