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

Convert to tabbed layout.

parent f7b5c371
No related branches found
No related tags found
No related merge requests found
...@@ -121,8 +121,6 @@ ghg_subset <- function(dt, auth_area = " Hampshire"){ ...@@ -121,8 +121,6 @@ ghg_subset <- function(dt, auth_area = " Hampshire"){
# add filter for categories with input$ # add filter for categories with input$
} }
ghg_subset2 <- function(dt, auth_area = " Hampshire", plot_year = 2018){ ghg_subset2 <- function(dt, auth_area = " Hampshire", plot_year = 2018){
dt <- dt %>% dt <- dt %>%
filter(dt$Name %in% auth_area, filter(dt$Name %in% auth_area,
...@@ -130,6 +128,12 @@ ghg_subset2 <- function(dt, auth_area = " Hampshire", plot_year = 2018){ ...@@ -130,6 +128,12 @@ ghg_subset2 <- function(dt, auth_area = " Hampshire", plot_year = 2018){
# add filter for categories with input$ # add filter for categories with input$
} }
ghg_subset3 <- function(dt, plot_year = 2018){
dt <- dt %>%
filter(dt$Year == plot_year)
# add filter for categories with input$
}
# to expand y axis # to expand y axis
expand_ggplot <- function(plot) { expand_ggplot <- function(plot) {
y_min <- floor(min(layer_data(plot)$y, na.rm=TRUE)) y_min <- floor(min(layer_data(plot)$y, na.rm=TRUE))
...@@ -165,19 +169,19 @@ ui <- fluidPage( ...@@ -165,19 +169,19 @@ ui <- fluidPage(
sliderInput("yearSlider", label = "Year", min = 2005, sliderInput("yearSlider", label = "Year", min = 2005,
max = 2018, value = 2018, step = 1, round = TRUE, max = 2018, value = 2018, step = 1, round = TRUE,
ticks = FALSE, width = "90%", sep = ""), ticks = FALSE, width = "90%", sep = ""),
plotOutput("plot", height = "400px"), tabsetPanel(
plotOutput("bar", height = "150px")) tabPanel("Authorities compared",
plotOutput("plot_by_auth", height = "500px")
), ),
tabPanel("Authority detail",
fluidRow( plotOutput("plot", height = "450px"),
column(5), plotOutput("bar", height = "150px")
column(7)
) )
)
)))
)
# *Input() functions # *Input() functions
# *Output() functions # *Output() functions
...@@ -187,7 +191,7 @@ server <- function(input, output, session) { ...@@ -187,7 +191,7 @@ server <- function(input, output, session) {
output$authmap <- renderLeaflet({ output$authmap <- renderLeaflet({
leaflet() %>% leaflet(options = leafletOptions(zoomControl = FALSE, minZoom = 9, maxZoom = 9)) %>%
addTiles() %>% # Add default OpenStreetMap map tiles addTiles() %>% # Add default OpenStreetMap map tiles
addPolygons(data = sf_data, layerId = ~(lad18nm), addPolygons(data = sf_data, layerId = ~(lad18nm),
color = "blue", fillColor = "blue", fillOpacity = 0.2, weight = 1.5, color = "blue", fillColor = "blue", fillOpacity = 0.2, weight = 1.5,
...@@ -283,6 +287,32 @@ server <- function(input, output, session) { ...@@ -283,6 +287,32 @@ server <- function(input, output, session) {
plot + expand_ggplot(plot) plot + expand_ggplot(plot)
}) })
output$plot_by_auth <- renderPlot({
plotTitle = paste0("Greenhouse gas emissions by sector for Hampshire local authorities: ",input$yearSlider)
ggplot() +
geom_col(ghg_subset3(dt = pc_detail_plot, plot_year = input$yearSlider),
mapping = aes(x = reorder(Name, desc(Name)), y = value, fill = variable), position = "stack") +
geom_col(ghg_subset3(dt = pc_totals_plot, plot_year = input$yearSlider),
mapping = aes(x = reorder(Name, desc(Name)), y = value, colour = variable), fill = "none", position = "stack") +
geom_hline(yintercept=0, lwd=0.4, colour="black", linetype = "dashed") +
coord_flip(ylim = c(-1,15)) +
#scale_y_continuous(labels=abs) +
#scale_x_continuous(breaks = 2005:2018) +
scale_color_manual(values = totals_pal, guide = FALSE) +
scale_fill_manual(values = detailed_pal) +
labs(x = "Local authority",
y = "Emissions per capita, tCO2",
fill = "Source",
title = plotTitle,
caption = plotCaption) +
theme(legend.position = "none") +
theme_classic()
})
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment