Repository for Petra's work at ampli Jan-Feb 2019

clusterviz.R 1.0KB

123456789101112131415161718192021222324252627
  1. library(reticulate)
  2. library(ggplot2)
  3. library(dplyr)
  4. theme_set(theme_bw())
  5. use_virtualenv("../venv/")
  6. p <- import("pandas")
  7. sns <- import("seaborn")
  8. cbp <- as.character(p$Series(sns$color_palette("colorblind", as.integer(9))$as_hex()))
  9. aggdf <- p$read_pickle("../data/9-clusters.agg.pkl")
  10. aggdf <- as.data.frame(aggdf)
  11. aggdf$cluster <- factor(aggdf$cluster)
  12. str(aggdf)
  13. ggplot(aggdf, aes(y = kwh_tot_mean, x = cluster)) + geom_boxplot()
  14. ggplot(aggdf, aes(x = read_time, y = kwh_tot_mean, color = cluster)) +
  15. geom_line() + facet_grid(cluster ~ .) +
  16. labs(title = "Cluster behaviour over full year", x = "Date and time", y = "kwh") +
  17. scale_color_manual(values = cbp)
  18. midjan <- filter(aggdf, read_time > as.POSIXct("2017-01-15"), read_time <= as.POSIXct("2017-01-21"))
  19. ggplot(midjan, aes(x = read_time, y = kwh_tot_mean, color = cluster)) +
  20. geom_line() + facet_grid(cluster ~ .) +
  21. labs(title = "Cluster behaviour over third week of January", x = "Date and time", y = "kwh") +
  22. scale_color_manual(values = cbp)