library(readr) raw <- read_csv("data/alt_fuel_stations (Sep 25 2024)_joined.csv") problems(raw) %>% print(n=Inf) library(tidyverse) dataset <- raw %>% select( `Station Name`, `City`, `EV Level2 EVSE Num`, `EV DC Fast Count`, `Latitude`, `Longitude`, `EV Connector Types`, `EV Workplace Charging`, `UR20` ) problems(dataset) %>% print(n=Inf) has_null_ur20 <- dataset %>% summarise(any_null = any(is.na(UR20))) dataset <- dataset %>% filter(!is.na(UR20)) %>% mutate(UR20 = recode(UR20, "R" = "Rural", "U" = "Urban")) %>% mutate('Total Chargers' = rowSums(select(., `EV Level2 EVSE Num`, `EV DC Fast Count`), na.rm = TRUE)) filtered_df <- dataset %>% filter(!is.na(`EV Level2 EVSE Num`) & !is.na(`EV DC Fast Count`)) library(ggplot2) library(scales) ggplot(dataset, aes(y = factor(UR20))) + geom_bar(aes(x = after_stat(count))) + geom_text(stat = 'count', aes(label = comma(after_stat(count))), # Use comma for thousands separators position = position_stack(vjust = 0.5), color = "white") + # Set label color to white labs(title = "Urban-Rural Station Histogram", x = "Classification", y = "Count") + theme_minimal() charger_by_UR20_summary <- dataset %>% group_by(UR20) %>% summarise(`Total Chargers` = sum(`Total Chargers`)) ggplot(charger_by_UR20_summary, aes(x = UR20, y = `Total Chargers`)) + geom_bar(stat = "identity", fill = "skyblue", color = "black") + geom_text(aes(label = comma(`Total Chargers`)), vjust = -0.5, size = 5) + # Label position labs(title = "Total Chargers by UR20", x = "UR20", y = "Total Chargers") + theme_minimal()