Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
spatialec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ben Anderson
spatialec
Commits
6bc92202
Commit
6bc92202
authored
6 years ago
by
Ben Anderson
Browse files
Options
Downloads
Patches
Plain Diff
added peak period shading to plots via new function; updated plots to give location
parent
9defb49d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
analysis/GREENGridModel/_loadPowerData.Rmd
+141
-39
141 additions, 39 deletions
analysis/GREENGridModel/_loadPowerData.Rmd
with
141 additions
and
39 deletions
analysis/GREENGridModel/_loadPowerData.Rmd
+
141
−
39
View file @
6bc92202
...
...
@@ -60,19 +60,49 @@ setkey(ggHwDT, linkID)
```
```{r hw.summary.overall}
amPeakStart <- hms::as.hms("07:00:00")
amPeakEnd <- hms::as.hms("09:00:00")
pmPeakStart <- hms::as.hms("16:00:00")
pmPeakEnd <- hms::as.hms("20:00:00")
rectAlpha <- 0.1
vLineAlpha <- 0.4
vLineCol <- "#0072B2" # http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/#a-colorblind-friendly-palette
myTextSize <- 3
addPeaks <- function(p){
# takes a plot, assumes qHour is hms, adds peak period annotations
# assumes you've set yMin & yMax already
# breaks with facet_grid, scales = "free" so you have to build seperate plots if you want to do that
# there is a complex solution (https://stackoverflow.com/questions/27898651/get-scales-range-of-facets-scales-free) but...
p <- p + annotate("rect", xmin = amPeakStart,
xmax = amPeakEnd,
ymin = yMin, ymax = yMax,
alpha = rectAlpha, fill = vLineCol)
p <- p + annotate("rect", xmin = pmPeakStart,
xmax = pmPeakEnd,
ymin = yMin, ymax = yMax,
alpha = rectAlpha, fill = vLineCol)
return(p)
}
plotDT <- ggHhDT[, .(linkID)][ggHwDT][, .(meanW = mean(powerW), # merge on linkID here as we summarise (data.table trick)
sdW = sd(powerW),
sumW = sum(powerW),
nObs = .N), keyby = .(qHour, season)]
ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = season)) +
p <-
ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = season)) +
geom_step() +
scale_colour_discrete(name = "Season") +
#scale_colour_viridis(discrete = TRUE) +
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = myCaption
caption =
paste0(
myCaption
, "\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
```
```{r hw.summary.presenceKids}
...
...
@@ -81,16 +111,18 @@ plotDT <- ggHhDT[, .(linkID, presenceKids)][ggHwDT][, .(meanW = mean(powerW),
sumW = sum(powerW),
nObs = .N), keyby = .(qHour, presenceKids, season)]
ggplot2::ggplot(plotDT[!is.na(presenceKids)], aes(x = qHour, y = meanW/1000, colour = presenceKids)) +
p <-
ggplot2::ggplot(plotDT[!is.na(presenceKids)], aes(x = qHour, y = meanW/1000, colour = presenceKids)) +
geom_step() +
scale_colour_discrete(name = "Presence of children") +
#scale_colour_viridis(discrete = TRUE) +
facet_grid(season ~ .) +
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = myCaption
caption =
paste0(
myCaption
, "\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
# need to count households per category for the actual data plotted
ggHwIDsDT <- ggHwDT[, .(nObs = .N), keyby = linkID]
...
...
@@ -109,15 +141,18 @@ plotDT <- ggHhDT[, .(linkID, nBedroomsCat)][ggHwDT][, .(meanW = mean(powerW),
sumW = sum(powerW),
nObs = .N), keyby = .(qHour, nBedroomsCat, season)]
ggplot2::ggplot(plotDT[!is.na(nBedroomsCat)], aes(x = qHour, y = meanW/1000, colour = nBedroomsCat)) +
p <-
ggplot2::ggplot(plotDT[!is.na(nBedroomsCat)], aes(x = qHour, y = meanW/1000, colour = nBedroomsCat)) +
geom_step() +
facet_grid(season ~ .) +
scale_colour_discrete(name = "N bedrooms") +
#scale_colour_viridis(discrete = TRUE) +
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = myCaption
caption =
paste0(
myCaption
, "\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
t <- ggHhDT[ggHwIDsDT][, .('N households' = uniqueN(linkID)),
keyby = .('N bedrooms' = nBedroomsCat)]
...
...
@@ -133,15 +168,17 @@ plotDT <- ggHhDT[, .(linkID, nPeopleCat)][ggHwDT][, .(meanW = mean(powerW),
sumW = sum(powerW),
nObs = .N), keyby = .(qHour, nPeopleCat, season)]
ggplot2::ggplot(plotDT[!is.na(nPeopleCat)], aes(x = qHour, y = meanW/1000, colour = nPeopleCat)) +
p <-
ggplot2::ggplot(plotDT[!is.na(nPeopleCat)], aes(x = qHour, y = meanW/1000, colour = nPeopleCat)) +
geom_step() +
scale_colour_discrete(name = "N people") +
#scale_colour_viridis(discrete = TRUE) +
facet_grid(season ~ .) +
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = myCaption
x = "Time of day",caption = paste0(myCaption, "\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
t <- ggHhDT[ggHwIDsDT][, .('N households' = uniqueN(linkID)),
keyby = .('N people' = nPeopleCat)]
...
...
@@ -157,7 +194,7 @@ plotDT <- ggHwDT[, .(meanW = mean(powerW),
nObs = .N), keyby = .(linkID, qHour, season)]
# aggregate plot per hh
ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = linkID)) +
p <-
ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = linkID)) +
geom_step() +
scale_colour_viridis(discrete = TRUE) +
facet_grid(season ~ .) +
...
...
@@ -165,7 +202,12 @@ ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = linkID)) +
x = "Time of day",
caption = paste0(myCaption,
"\n Hot Water circuits, n = ",
uniqueN(ggHwDT$circuit)))
uniqueN(ggHwDT$circuit),
"\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
```
```{r hw.season.byLocation}
...
...
@@ -178,14 +220,19 @@ plotDT <- ggHhDT[, .(linkID, Location)][ggHwDT][, .(meanW = mean(powerW),
nObs = .N), keyby = .(qHour, Location)]
# aggregate plot over all households
ggplot2::ggplot(plotDT[!is.na(Location)], aes(x = qHour, y = meanW/1000, colour = Location)) +
p <-
ggplot2::ggplot(plotDT[!is.na(Location)], aes(x = qHour, y = meanW/1000, colour = Location)) +
geom_step() +
#scale_colour_viridis(discrete = TRUE) +
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = paste0(myCaption,
"\n Hot Water circuits: n = ",
uniqueN(ggHwDT$linkID)))
uniqueN(ggHwDT$linkID),
"\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
```
## Heat Pump
...
...
@@ -249,14 +296,18 @@ plotDT <- ggHhDT[, .(linkID)][ggHpDT][, .(meanW = mean(powerW),
sumW = sum(powerW),
nObs = .N), keyby = .(qHour, season)]
ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = season)) +
p <-
ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = season)) +
geom_step() +
scale_colour_discrete(name = "Season") +
#scale_colour_viridis(discrete = TRUE) +
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = myCaption
caption = paste0(myCaption,
"\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
```
```{r hp.summary.charts.presenceKids}
...
...
@@ -266,16 +317,21 @@ plotDT <- ggHhDT[, .(linkID, presenceKids)][ggHpDT][, .(meanW = mean(powerW),
sumW = sum(powerW),
nObs = .N), keyby = .(qHour, presenceKids, season)]
ggplot2::ggplot(plotDT[!is.na(presenceKids)], aes(x = qHour, y = meanW/1000, colour = presenceKids)) +
p <-
ggplot2::ggplot(plotDT[!is.na(presenceKids)], aes(x = qHour, y = meanW/1000, colour = presenceKids)) +
geom_step() +
scale_colour_discrete(name = "Presence of children") +
#scale_colour_viridis(discrete = TRUE) +
facet_grid(season ~ .)
facet_grid(season ~ .)
+
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = paste0(myCaption,
"\n Heat pumps, n = ",
uniqueN(ggHpDT$linkID)))
uniqueN(ggHpDT$linkID),
"\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
# need to count households per category for the actual data plotted
ggHpIDsDT <- ggHpDT[, .(nObs = .N), keyby = linkID]
...
...
@@ -295,15 +351,19 @@ plotDT <- ggHhDT[, .(linkID, nBedroomsCat)][ggHpDT][, .(meanW = mean(powerW),
sumW = sum(powerW),
nObs = .N), keyby = .(qHour, nBedroomsCat, season)]
ggplot2::ggplot(plotDT[!is.na(nBedroomsCat)], aes(x = qHour, y = meanW/1000, colour = nBedroomsCat)) +
p <-
ggplot2::ggplot(plotDT[!is.na(nBedroomsCat)], aes(x = qHour, y = meanW/1000, colour = nBedroomsCat)) +
geom_step() +
scale_colour_discrete(name = "N bedrooms") +
#scale_colour_viridis(discrete = TRUE) +
facet_grid(season ~ .) +
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = myCaption
caption = paste0(myCaption,
"\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
t <- ggHhDT[ggHpIDsDT][, .('N households' = uniqueN(linkID)),
keyby = .('N bedrooms' = nBedroomsCat)]
...
...
@@ -319,15 +379,19 @@ plotDT <- ggHhDT[, .(linkID, nPeopleCat)][ggHpDT][, .(meanW = mean(powerW),
sumW = sum(powerW),
nObs = .N), keyby = .(qHour, nPeopleCat, season)]
ggplot2::ggplot(plotDT[!is.na(nPeopleCat)], aes(x = qHour, y = meanW/1000, colour = nPeopleCat)) +
p <-
ggplot2::ggplot(plotDT[!is.na(nPeopleCat)], aes(x = qHour, y = meanW/1000, colour = nPeopleCat)) +
geom_step() +
scale_colour_discrete(name = "N people") +
#scale_colour_viridis(discrete = TRUE) +
facet_grid(season ~ .) +
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = myCaption
caption = paste0(myCaption,
"\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
t <- ggHhDT[ggHpIDsDT][, .('N households' = uniqueN(linkID)),
keyby = .('N people' = nPeopleCat)]
...
...
@@ -343,7 +407,7 @@ plotDT <- ggHpDT[, .(meanW = mean(powerW),
nObs = .N), keyby = .(linkID, qHour, season)]
# aggregate plot per hh
ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = linkID)) +
p <-
ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = linkID)) +
geom_step() +
scale_colour_viridis(discrete = TRUE) +
facet_grid(season ~ .) +
...
...
@@ -351,7 +415,12 @@ ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = linkID)) +
x = "Time of day",
caption = paste0(myCaption,
"\n Heat Pump circuits, n = ",
uniqueN(ggHpDT$circuit)))
uniqueN(ggHpDT$circuit),
"\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
```
```{r hp.season.byLocation}
...
...
@@ -364,14 +433,19 @@ plotDT <- ggHhDT[, .(linkID, Location)][ggHpDT][, .(meanW = mean(powerW),
nObs = .N), keyby = .(qHour, Location)]
# aggregate plot over all households
ggplot2::ggplot(plotDT[!is.na(Location)], aes(x = qHour, y = meanW/1000, colour = Location)) +
p <-
ggplot2::ggplot(plotDT[!is.na(Location)], aes(x = qHour, y = meanW/1000, colour = Location)) +
geom_step() +
#scale_colour_viridis(discrete = TRUE) +
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = paste0(myCaption,
"\n Heat Pump circuits: n = ",
uniqueN(ggHpDT$linkID)))
uniqueN(ggHpDT$linkID),
"\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
```
## Lighting
...
...
@@ -439,13 +513,18 @@ plotDT <- ggHhDT[, .(linkID)][ggLightingDT][, .(meanW = mean(powerW),
sumW = sum(powerW),
nObs = .N), keyby = .(qHour, season)]
ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = season)) +
p <-
ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = season)) +
geom_step() +
scale_colour_discrete(name = "Season") +
#scale_colour_viridis(discrete = TRUE) +
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = myCaption)
caption = paste0(myCaption,
"\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
```
```{r l.summary.charts.presenceKids}
...
...
@@ -455,14 +534,19 @@ plotDT <- ggHhDT[, .(linkID, presenceKids)][ggLightingDT][, .(meanW = mean(power
sumW = sum(powerW),
nObs = .N), keyby = .(qHour, presenceKids, season)]
ggplot2::ggplot(plotDT[!is.na(presenceKids)], aes(x = qHour, y = meanW/1000, colour = presenceKids)) +
p <-
ggplot2::ggplot(plotDT[!is.na(presenceKids)], aes(x = qHour, y = meanW/1000, colour = presenceKids)) +
geom_step() +
scale_colour_discrete(name = "Presence of children") +
#scale_colour_viridis(discrete = TRUE) +
facet_grid(season ~ .) +
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = myCaption)
caption = paste0(myCaption,
"\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
# need to count households per category for the actual data plotted
ggLightingIDsDT <- ggLightingDT[, .(nObs = .N), keyby = linkID]
...
...
@@ -482,15 +566,19 @@ plotDT <- ggHhDT[, .(linkID, nBedroomsCat)][ggLightingDT][, .(meanW = mean(power
sumW = sum(powerW),
nObs = .N), keyby = .(qHour, nBedroomsCat, season)]
ggplot2::ggplot(plotDT[!is.na(nBedroomsCat)], aes(x = qHour, y = meanW/1000, colour = nBedroomsCat)) +
p <-
ggplot2::ggplot(plotDT[!is.na(nBedroomsCat)], aes(x = qHour, y = meanW/1000, colour = nBedroomsCat)) +
geom_step() +
scale_colour_discrete(name = "N bedrooms") +
#scale_colour_viridis(discrete = TRUE) +
facet_grid(season ~ .) +
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = myCaption
caption = paste0(myCaption,
"\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
t <- ggHhDT[ggLightingIDsDT][, .('N households' = uniqueN(linkID)),
keyby = .('N bedrooms' = nBedroomsCat)]
...
...
@@ -506,15 +594,19 @@ plotDT <- ggHhDT[, .(linkID, nPeopleCat)][ggLightingDT][, .(meanW = mean(powerW)
sumW = sum(powerW),
nObs = .N), keyby = .(qHour, nPeopleCat, season)]
ggplot2::ggplot(plotDT[!is.na(nPeopleCat)], aes(x = qHour, y = meanW/1000, colour = nPeopleCat)) +
p <-
ggplot2::ggplot(plotDT[!is.na(nPeopleCat)], aes(x = qHour, y = meanW/1000, colour = nPeopleCat)) +
geom_step() +
scale_colour_discrete(name = "N people") +
#scale_colour_viridis(discrete = TRUE) +
facet_grid(season ~ .) +
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = myCaption
caption = paste0(myCaption,
"\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
t <- ggHhDT[ggLightingIDsDT][, .('N households' = uniqueN(linkID)),
keyby = .('N people' = nPeopleCat)]
...
...
@@ -531,7 +623,7 @@ plotDT <- ggLightingDT[, .(meanW = mean(powerW),
nObs = .N), keyby = .(linkID, qHour, season)]
# aggregate plot per hh
ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = linkID)) +
p <-
ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = linkID)) +
geom_step() +
scale_colour_viridis(discrete = TRUE) +
facet_grid(season ~ .) +
...
...
@@ -539,7 +631,12 @@ ggplot2::ggplot(plotDT, aes(x = qHour, y = meanW/1000, colour = linkID)) +
x = "Time of day",
caption = paste0(myCaption,
"\n Lighting circuits, n = ",
uniqueN(ggLightingDT$circuit)))
uniqueN(ggLightingDT$circuit),
"\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
```
```{r l.season.byLocation}
...
...
@@ -552,14 +649,19 @@ plotDT <- ggHhDT[, .(linkID, Location)][ggLightingDT][, .(meanW = mean(powerW),
nObs = .N), keyby = .(qHour, Location)]
# aggregate plot over all households
ggplot2::ggplot(plotDT[!is.na(Location)], aes(x = qHour, y = meanW/1000, colour = Location)) +
p <-
ggplot2::ggplot(plotDT[!is.na(Location)], aes(x = qHour, y = meanW/1000, colour = Location)) +
geom_step() +
#scale_colour_viridis(discrete = TRUE) +
labs(y = "Mean kW (across households)",
x = "Time of day",
caption = paste0(myCaption,
"\n Lighting circuits: n = ",
uniqueN(ggLightingDT$linkID)))
uniqueN(ggLightingDT$linkID),
"\n Peak demand periods shaded")
)
yMin <- min(plotDT$meankW)
yMax <- max(plotDT$meankW)
addPeaks(p)
```
```{r runToHere}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment