Skip to content
Snippets Groups Projects
Commit c707a074 authored by Tom Rushby's avatar Tom Rushby
Browse files

fix strip bar plot single LA & year.

parent 7de3a464
No related branches found
No related tags found
No related merge requests found
...@@ -134,6 +134,11 @@ ghg_subset <- function(dt, auth_area = "Southampton"){ ...@@ -134,6 +134,11 @@ ghg_subset <- function(dt, auth_area = "Southampton"){
} }
# Construct plots ---- # Construct plots ----
plotCaption = paste0("Emissions data: Department for Business, Energy & Industrial Strategy",
"\nUK local authority and regional carbon dioxide emissions national statistics: 2005 to 2018",
"\nVisualisation: t.w.rushby@soton.ac.uk | energy.soton.ac.uk")
# Emissions by year for each local authority
i <- 1 i <- 1
plotNames <- list() plotNames <- list()
...@@ -141,10 +146,6 @@ for (auth_area in las_to_load) { ...@@ -141,10 +146,6 @@ for (auth_area in las_to_load) {
plotName <- paste0("laemissions_by_year_",gsub("[[:space:]]", "_", auth_area)) plotName <- paste0("laemissions_by_year_",gsub("[[:space:]]", "_", auth_area))
plotCaption = paste0("Emissions data: Department for Business, Energy & Industrial Strategy",
"\nUK local authority and regional carbon dioxide emissions national statistics: 2005 to 2018",
"\nVisualisation: t.w.rushby@soton.ac.uk | energy.soton.ac.uk")
plotTitle = paste0("Greenhouse gas emissions by source: ",auth_area) plotTitle = paste0("Greenhouse gas emissions by source: ",auth_area)
plot_data1 <- ghg_subset(pc_detail_plot, auth_area = auth_area) plot_data1 <- ghg_subset(pc_detail_plot, auth_area = auth_area)
...@@ -176,8 +177,9 @@ i <- i+1 ...@@ -176,8 +177,9 @@ i <- i+1
print(plotNames) print(plotNames)
# By local authority # Emissions by local authority
years_to_plot <- c(2005,2018) years_to_plot <- c(2005,2018)
plot_year <- 2018
for(plot_year in years_to_plot) { for(plot_year in years_to_plot) {
...@@ -210,6 +212,34 @@ for(plot_year in years_to_plot) { ...@@ -210,6 +212,34 @@ for(plot_year in years_to_plot) {
} }
# Emissions for single local authority
plot_data1 <- pc_detail_plot %>% filter(Year == plot_year & Name == auth_area)
plot_data2 <- pc_totals_plot %>% filter(Year == plot_year & Name == auth_area)
x_min <- floor(min(plot_data2$value))
x_max <- ceiling(sum(plot_data2$value))
plot <- ggplot() +
geom_col(data = plot_data1, aes(x = Name, y = value, fill = variable), position = "stack") +
#geom_col(data = plot_data2, aes(x = Name, y = value, colour = variable), fill = NA, position = "stack") +
geom_hline(yintercept=0, lwd=0.4, colour="black", linetype = "dashed") +
coord_flip(ylim = c(x_min,x_max)) +
scale_y_continuous(breaks = x_min:x_max) +
scale_color_manual(values = totals_pal) +
scale_fill_manual(values = detailed_pal) +
theme_minimal() +
labs(y = "Emissions per capita (tonnes of carbon dioxide/person)") +
theme(axis.text.y = element_blank(),
axis.title.y = element_blank(),
axis.ticks.y = element_blank(),
#axis.title.x = element_blank(),
panel.grid.major.y = element_blank(),
legend.position = "none")
ggplotly(plot)
ggplot() + ggplot() +
geom_col(data = plot_data1, aes(x = Name, y = value, fill = variable), position = "stack") + geom_col(data = plot_data1, aes(x = Name, y = value, fill = variable), position = "stack") +
geom_col(data = plot_data2, aes(x = Name, y = value, colour = variable), fill = "none", position = "stack") + geom_col(data = plot_data2, aes(x = Name, y = value, colour = variable), fill = "none", position = "stack") +
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment