How can I add a third variable to a bar plot? I'm new to R so tidyverse and ggplot is still a bit confusing for me.
library(tidyverse)
library(plotly)
library(stringr)
fines %>%
filter(IF_SPEEDING == "Y" & LOCATION != "" & SPEED_BAND != "") %>%
group_by(LOCATION) %>%
summarise(
`Number LOCATION` = n()
) %>%
arrange(
-(`Number LOCATION`)
) %>%
filter( `Number LOCATION` > 800) -> LOCATION_OVER_800
LOCATION_OVER_800 %>%
ggplot(aes(x = LOCATION, y = `LOCATION_OVER_800` )) +
geom_bar(aes(fill=SPEED_BAND), stat = "identity") +
theme(axis.text.x = element_text (angle = 45)) +
labs(
title = "Locations of issued fine and speeding severity",
x = 'Location',
y = 'Number of fines'
) -> p
ggplotly(p)