Overview
- Data from the Department of the Environment and Energy
- Energy intensity - amount of energy used to produce a unit of economic output (energy consumption/GDP)
- Energy productivity - economic output produced per unit of energy input (GDP/energy consumption)
# Bug
knitr::include_app("https://yihui.shinyapps.io/miniUI/",
height = "600px")
animate_plot <- tbl_2_4_energy_consumption_sector_level %>%
ggplot(aes(x = rank, group = Sectors, fill = as.factor(Sectors), colour = as.factor(Sectors))) +
geom_bar(aes(y = as.integer(round(Consumption, 0))), stat = "identity", position = "identity") +
geom_text(aes(y = 0, label = paste(Sectors, " ")), vjust = 0.2, hjust = 1) +
theme_bw() +
theme(legend.position = "none",
axis.ticks.y = element_blank(),
axis.text.y = element_blank(),
axis.title.y = element_blank(),
plot.margin = margin(1,1,1,5, "cm")) +
coord_flip(clip = "off", expand = FALSE) +
scale_y_continuous(labels = scales::comma) +
scale_x_reverse() +
geom_text(aes(y = Consumption, label = as.character(round(Consumption, 0))), colour = "black", vjust = 0.2, hjust = -0.5) +
labs(title = "Australian energy consumption by sector, {closest_state}") +
transition_states(Year, transition_length = 30,
state_length = 20,
wrap = FALSE) +
ease_aes('linear') +
enter_fade() +
exit_fade()
animate(animate_plot, fps = 10, duration = 20, width = 800, height = 450)
# Load networkD3
library(networkD3)
# Create edge list with energy flow (US)
energy_to_elecheatplant_2017_US <- IEA_data %>%
filter(Country == "United States", Flow == "Electricity, CHP and heat plants (ktoe)", !Product %in% c("Total", "Electricity", "Heat")) %>%
mutate(`2017` = abs(`2017`)) %>%
select(Product, Flow, `2017`)
# Create edge list with electricity & heat plant flow (US)
elecheatplant_to_elecheat_2017_US <- IEA_data %>%
filter(Country == "United States", Flow == "Electricity, CHP and heat plants (ktoe)", Product %in% c("Electricity", "Heat")) %>%
rename(Product = Flow, Flow = Product) %>%
select(Product, Flow, `2017`)
# Create edge list with electricity & heat flow (US)
elecheat_to_sector_2017_US <- IEA_data %>%
filter(Country == "United States", Product %in% c("Electricity", "Heat"), Flow %in% c("Industry (ktoe)", "Transport (ktoe)", "Residential (ktoe)", "Commercial and public services (ktoe)", "Other final consumption (ktoe)")) %>%
select(Product, Flow, `2017`)
# Create total energy input
country_energy_input_2017 <- IEA_data %>%
filter(Flow %in% c("Electricity, CHP and heat plants (ktoe)", "Total final consumption (ktoe)"),
!Product %in% c("Electricity", "Heat", "Total"),
Flow != "Total final consumption (ktoe)") %>%
select(Country, Product, Flow, `2017`) %>%
group_by(Country) %>%
# energy input into electricity and heat plants
mutate(energy_input = abs(sum(`2017`))) %>%
ungroup() %>%
select(-`2017`) %>%
rename(`2017` = energy_input) %>%
mutate(Product = "Total Input", Flow = "Electricity, CHP and heat plants (ktoe)") %>%
distinct()
# Create edge list with electricity & heat plant to rejected energy
elecheatplant_to_rejected_2017 <- IEA_data %>%
filter(Flow == "Total final consumption (ktoe)" & Product %in% c("Electricity", "Heat")) %>%
select(Country, Product, Flow, `2017`) %>%
bind_rows(country_energy_input_2017) %>%
arrange(Country) %>%
group_by(Country) %>%
mutate(rejected_energy = nth(`2017`, n = 3) - nth(`2017`, n = 2) - first(`2017`)) %>%
ungroup() %>%
select(-`2017`) %>%
rename(`2017` = rejected_energy) %>%
mutate(Product = "Electricity, CHP and heat plants (ktoe)",
Flow = "Rejected Energy") %>%
distinct()
elecheatplant_to_rejected_2017_US <- elecheatplant_to_rejected_2017 %>%
filter(Country == "United States") %>%
select(-Country)
# Row bind above edge list tables
sankey_data <- energy_to_elecheatplant_2017_US %>%
bind_rows(elecheatplant_to_elecheat_2017_US, elecheat_to_sector_2017_US, elecheatplant_to_rejected_2017_US) %>%
# Electricity and heat plants are the source that flows to the target: elec & heat
rename(source = Product, target = Flow, value = `2017`)
# Create a node data frame (contains all entities in the edge list)
node <- data.frame(
name=c(as.character(sankey_data$source),
as.character(sankey_data$target)) %>% unique()
)
# With networkD3, connection must be provided using id, not using real name like in the links dataframe, so we need to reformat it
sankey_data$IDsource <- match(sankey_data$source, node$name)-1
sankey_data$IDtarget <- match(sankey_data$target, node$name)-1
# Make the Network
sankey_plot <- sankeyNetwork(Links = sankey_data, Nodes = node,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
sinksRight=FALSE)
sankey_plot
To-do: network diagram, sector + electricity consumption by energy source