Electric_Vehicle_Population

Author

Zijin Wang

This dataset shows the Battery Electric Vehicles (BEVs) and Plug-in Hybrid Electric Vehicles (PHEVs) that are currently registered through Washington State Department of Licensing (DOL)

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.3     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
electric_vehicle_data <- read_csv("/Users/zwang30/Downloads/Electric_Vehicle_Population_Data.csv")
Rows: 159467 Columns: 17
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (11): VIN (1-10), County, City, State, Make, Model, Electric Vehicle Typ...
dbl  (6): Postal Code, Model Year, Electric Range, Base MSRP, Legislative Di...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
electric_vehicle_data <- electric_vehicle_data %>%
  mutate(`Model Year` = as.numeric(`Model Year`),
         `Electric Range` = as.numeric(`Electric Range`))
recent_evs <- electric_vehicle_data %>%
  filter(`Model Year` >= 2015) %>%
  group_by(Make) %>%
  filter(n() > 200) %>%
  ungroup() 
ggplot(recent_evs, aes(x = `Model Year`, y = `Electric Range`, color = Make)) +
  geom_jitter(alpha = 0.5, width = 0.2, height = 0) +  # Using jitter to avoid overplotting
  facet_wrap(~Make, scales = "free_y", ncol = 4) +  # Set number of columns to avoid squeezed facets
  scale_color_viridis_d() +
  labs(title = "Electric Vehicle Range by Make and Model Year",
       x = "Model Year",
       y = "Electric Range (miles)",
       color = "Make") +
  theme_minimal() +
  theme(legend.position = "bottom",
        axis.text.x = element_text(angle = 45, hjust = 1),
        plot.title = element_text(size = 14, face = "bold"),
        strip.text.x = element_text(size = 10, face = "bold")) +
  guides(color = guide_legend(override.aes = list(size=4)))

ggsave("EV_Range_Plot.png", width = 20, height = 15, units = "cm")