123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- library(reticulate)
- library(ggplot2)
- library(dplyr)
- theme_set(theme_bw())
- use_virtualenv("../venv/")
-
- p <- import("pandas")
- sns <- import("seaborn")
- cbp <- as.character(p$Series(sns$color_palette("colorblind", as.integer(9))$as_hex()))
- aggdf <- p$read_pickle("../data/9-clusters.agg.pkl")
- aggdf <- as.data.frame(aggdf)
- aggdf$cluster <- factor(aggdf$cluster)
- str(aggdf)
-
- ggplot(aggdf, aes(y = kwh_tot_mean, x = cluster)) + geom_boxplot()
-
- facall <- ggplot(aggdf, aes(x = read_time, y = kwh_tot_mean, color = cluster, fill = cluster)) +
- geom_line(size = 1.5) + geom_ribbon(aes(ymin = kwh_tot_CI_low, ymax = kwh_tot_CI_high), alpha = 0.2, color = NA) +
- labs(title = "Cluster behaviour over full year, 2017", x = "Date", y = "kwh") +
- scale_color_manual(values = cbp) +
- scale_fill_manual(values = cbp) +
- theme(legend.position = "none") +
- scale_x_datetime(date_breaks = "1 month", date_labels = "%-d %B")
-
- allcon <- facall + facet_grid(cluster ~ .)
- allfre <- facall + facet_grid(cluster ~ ., scales = "free")
-
- midjan <- filter(aggdf, read_time >= as.POSIXct("2017-01-15", tz = "UTC"), read_time <= as.POSIXct("2017-01-22", tz = "UTC"))
-
- facjan <- ggplot(midjan, aes(x = read_time, y = kwh_tot_mean, color = cluster, fill = cluster)) +
- geom_line(size = 1.5) + geom_ribbon(aes(ymin = kwh_tot_CI_low, ymax = kwh_tot_CI_high), alpha = 0.2, color = NA) +
- labs(title = "Cluster behaviour over third week of January", x = "Date", y = "kwh") +
- scale_color_manual(values = cbp) +
- scale_fill_manual(values = cbp) +
- theme(legend.position = "none") +
- scale_x_datetime(date_breaks = "1 day", date_labels = "%a, %-d %B %Y")
-
- jancon <- facjan + facet_grid(cluster ~ .)
- janfre <- facjan + facet_grid(cluster ~ ., scales = "free")
-
-
- midap <- filter(aggdf, read_time >= as.POSIXct("2017-04-16", tz = "UTC"), read_time <= as.POSIXct("2017-04-23", tz = "UTC"))
-
- facap <- ggplot(midap, aes(x = read_time, y = kwh_tot_mean, color = cluster, fill = cluster)) +
- geom_line(size = 1.5) + geom_ribbon(aes(ymin = kwh_tot_CI_low, ymax = kwh_tot_CI_high), alpha = 0.2, color = NA) +
- labs(title = "Cluster behaviour over third week of April 2017", x = "Date", y = "kwh") +
- scale_color_manual(values = cbp) +
- scale_fill_manual(values = cbp) +
- theme(legend.position = "none") +
- scale_x_datetime(date_breaks = "1 day", date_labels = "%a, %-d %B %Y")
-
- apcon <- facap + facet_grid(cluster ~ .)
- apfre <- facap + facet_grid(cluster ~ ., scales = "free")
-
-
- midjul <- filter(aggdf, read_time >= as.POSIXct("2017-07-16", tz = "UTC"), read_time <= as.POSIXct("2017-07-23", tz = "UTC"))
-
- facjul <- ggplot(midjul, aes(x = read_time, y = kwh_tot_mean, color = cluster, fill = cluster)) +
- geom_line(size = 1.5) + geom_ribbon(aes(ymin = kwh_tot_CI_low, ymax = kwh_tot_CI_high), alpha = 0.2, color = NA) +
- labs(title = "Cluster behaviour over third week of July 2017", x = "Date", y = "kwh") +
- scale_color_manual(values = cbp) +
- scale_fill_manual(values = cbp) +
- theme(legend.position = "none") +
- scale_x_datetime(date_breaks = "1 day", date_labels = "%a, %-d %B %Y")
-
- julcon <- facjul + facet_grid(cluster ~ .)
- julfre <- facjul + facet_grid(cluster ~ ., scales = "free")
-
-
- midoct <- filter(aggdf, read_time >= as.POSIXct("2017-10-15", tz = "UTC"), read_time <= as.POSIXct("2017-10-22", tz = "UTC"))
-
- facoct <- ggplot(midoct, aes(x = read_time, y = kwh_tot_mean, color = cluster, fill = cluster)) +
- geom_line(size = 1.5) + geom_ribbon(aes(ymin = kwh_tot_CI_low, ymax = kwh_tot_CI_high), alpha = 0.2, color = NA) +
- labs(title = "Cluster behaviour over third week of October 2017", x = "Date", y = "kwh") +
- scale_color_manual(values = cbp) +
- scale_fill_manual(values = cbp) +
- theme(legend.position = "none") +
- scale_x_datetime(date_breaks = "1 day", date_labels = "%a, %-d %B %Y")
-
- octcon <- facoct + facet_grid(cluster ~ .)
- octfre <- facoct + facet_grid(cluster ~ ., scales = "free")
-
- ggsave("all-9-fix.png", allcon, path = "../img/", dpi = "retina", width = 40, height = 25, units = "cm")
- ggsave("all-9-fre.png", allfre, path = "../img/", dpi = "retina", width = 40, height = 25, units = "cm")
- ggsave("jan-9-fix.png", jancon, path = "../img/", dpi = "retina", width = 40, height = 25, units = "cm")
- ggsave("jan-9-fre.png", janfre, path = "../img/", dpi = "retina", width = 40, height = 25, units = "cm")
- ggsave("apr-9-fix.png", apcon, path = "../img/", dpi = "retina", width = 40, height = 25, units = "cm")
- ggsave("apr-9-fre.png", apfre, path = "../img/", dpi = "retina", width = 40, height = 25, units = "cm")
- ggsave("jul-9-fix.png", julcon, path = "../img/", dpi = "retina", width = 40, height = 25, units = "cm")
- ggsave("jul-9-fre.png", julfre, path = "../img/", dpi = "retina", width = 40, height = 25, units = "cm")
- ggsave("oct-9-fix.png", octcon, path = "../img/", dpi = "retina", width = 40, height = 25, units = "cm")
- ggsave("oct-9-fre.png", octfre, path = "../img/", dpi = "retina", width = 40, height = 25, units = "cm")
|