|
@@ -4,16 +4,25 @@ library(scales)
|
4
|
4
|
library(tidyverse)
|
5
|
5
|
library(readxl)
|
6
|
6
|
library(shinycssloaders)
|
|
7
|
+library(RColorBrewer)
|
7
|
8
|
|
8
|
9
|
# Original data from
|
9
|
10
|
# https://catalogue.data.govt.nz/dataset/
|
10
|
11
|
# new-zealands-energy-outlook/resource/3caad31e-aa96-4c94-8f54-1000518a0690?inner_span=True
|
11
|
12
|
|
|
13
|
+# Data loading ----
|
12
|
14
|
Emissions.Sector <- read_excel("Emissions1990-2010.xlsx",
|
13
|
15
|
sheet = "Sector")
|
14
|
16
|
Emissions.Fuel <- read_excel("Emissions1990-2010.xlsx",
|
15
|
17
|
sheet = "Fuel")
|
|
18
|
+sector.col <- data.frame(Sector=sectors.a,
|
|
19
|
+ col=brewer.pal(length(sectors.a), "Set3"))
|
|
20
|
+Emissions.Sector <- left_join(Emissions.Sector, sector.col) %>%
|
|
21
|
+ mutate(col = as.character(col))
|
16
|
22
|
Sector.Tot <- filter(Emissions.Sector, Source == "Total")
|
|
23
|
+Emissions.Fuel <- cbind(Emissions.Fuel,
|
|
24
|
+ col=brewer.pal(nrow(Emissions.Fuel), "Set2")) %>%
|
|
25
|
+ mutate(col=as.character(col))
|
17
|
26
|
|
18
|
27
|
sectors.a <- unique(Emissions.Sector$Sector)
|
19
|
28
|
sectors <- unique(Emissions.Sector$Sector)[-1]
|
|
@@ -110,9 +119,10 @@ server <- function(input, output) {
|
110
|
119
|
sov <- SecOverall()
|
111
|
120
|
if (input$secyears[1] != input$secyears[2]) {
|
112
|
121
|
ggplot(sov, aes(x=Year,
|
113
|
|
- y=Co2eqv, linetype=Sector, color=Sector)) -> s.p
|
|
122
|
+ y=Co2eqv, color=Sector)) -> s.p
|
114
|
123
|
s.p + geom_line(size=1.5, na.rm=TRUE) -> s.p
|
115
|
124
|
s.p + theme_linedraw() -> s.p
|
|
125
|
+ s.p + scale_color_manual(values=unique(sov$col)) -> s.p
|
116
|
126
|
} else {
|
117
|
127
|
ggplot(sov, aes(x=Sector,
|
118
|
128
|
y=Co2eqv, fill=Sector)) -> s.p
|
|
@@ -120,6 +130,7 @@ server <- function(input, output) {
|
120
|
130
|
s.p + theme_linedraw() -> s.p
|
121
|
131
|
s.p + theme(axis.text.x = element_text(
|
122
|
132
|
angle = -30, hjust = 0, vjust = 0)) -> s.p
|
|
133
|
+ s.p + scale_fill_manual(values=unique(sov$col)) -> s.p
|
123
|
134
|
}
|
124
|
135
|
s.p + guides(linetype=guide_legend(keywidth = 5)) -> s.p
|
125
|
136
|
s.p + theme(legend.position = "right",
|
|
@@ -158,9 +169,10 @@ server <- function(input, output) {
|
158
|
169
|
fov <- FuOverall()
|
159
|
170
|
if (input$fuyears[1] != input$fuyears[2]) {
|
160
|
171
|
ggplot(fov, aes(x=Year,
|
161
|
|
- y=Co2eqv, linetype=Fuel, color=Fuel)) -> f.p
|
|
172
|
+ y=Co2eqv, color=Fuel)) -> f.p
|
162
|
173
|
f.p + geom_line(size=1.5, na.rm=TRUE) -> f.p
|
163
|
174
|
f.p + theme_linedraw() -> f.p
|
|
175
|
+ f.p + scale_color_manual(values=unique(fov$col)) -> f.p
|
164
|
176
|
} else {
|
165
|
177
|
ggplot(fov, aes(x=Fuel,
|
166
|
178
|
y=Co2eqv, fill=Fuel)) -> f.p
|
|
@@ -168,6 +180,7 @@ server <- function(input, output) {
|
168
|
180
|
f.p + theme_linedraw() -> f.p
|
169
|
181
|
f.p + theme(axis.text.x = element_text(
|
170
|
182
|
angle = -30, hjust = 0, vjust = 0)) -> f.p
|
|
183
|
+ f.p + scale_fill_manual(values=unique(fov$col)) -> f.p
|
171
|
184
|
}
|
172
|
185
|
f.p + guides(linetype=guide_legend(keywidth = 5)) -> f.p
|
173
|
186
|
f.p + theme(legend.position = "right",
|