diff --git a/howTo/openGeogAPI/local_auth_ghg_plots.R b/howTo/openGeogAPI/local_auth_ghg_plots.R index 26acc4679273503ad9ed5594c63862471ffd489a..d759f77e906915393b937628003c1ad77bb90a13 100644 --- a/howTo/openGeogAPI/local_auth_ghg_plots.R +++ b/howTo/openGeogAPI/local_auth_ghg_plots.R @@ -134,6 +134,11 @@ ghg_subset <- function(dt, auth_area = "Southampton"){ } # 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 plotNames <- list() @@ -141,10 +146,6 @@ for (auth_area in las_to_load) { 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) plot_data1 <- ghg_subset(pc_detail_plot, auth_area = auth_area) @@ -176,8 +177,9 @@ i <- i+1 print(plotNames) -# By local authority +# Emissions by local authority years_to_plot <- c(2005,2018) +plot_year <- 2018 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() + 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") +