Story :
Transition between gas and electric cars
Hybrid or pure electric (proportion changes) – Brand preference
cars <- read.csv("Downloads/Electric_Vehicle_Population_Data_20260122.csv")
# Features of interest :
mdl_yr <- cars$Model.Year
make <- cars$Make
Electric <- cars$Electric.Vehicle.Type
cars <- cars |> dplyr::select(Model.Year, Make, Electric.Vehicle.Type)
library(tidyverse)
# Generate sentiment labels :
cars <- cars |>
mutate(Car.Category = case_when(
Make %in% c("BMW", "MERCEDES-BENZ", "AUDI", "ACURA", "CADILLAC", "LEXUS", "VOLVO",
"LINCOLN", "GENESIS", "JAGUAR", "LAND ROVER", "ALFA ROMEO", "MASERATI",
"ROLLS-ROYCE", "BENTLEY") ~ "Luxury",
Make %in% c("PORSCHE", "TESLA", "FISKER", "RIVIAN", "POLESTAR", "LUCID", "LAMBORGHINI") ~ "Sports",
Make %in% c("TOYOTA", "HONDA", "HYUNDAI", "KIA", "MAZDA", "NISSAN", "CHEVROLET", "FORD",
"VOLKSWAGEN", "FIAT", "SMART", "MINI", "SUBARU") ~ "Economy",
Make %in% c("RAM", "GMC", "JEEP", "CHRYSLER", "DODGE", "BRIGHTDROP") ~ "Truck/Utility",
Make %in% c("WHEEGO ELECTRIC CARS", "TH!NK", "AZURE DYNAMICS",
"MULLEN AUTOMOTIVE INC.", "VINFAST") ~ "Niche EV",
TRUE ~ "Other"
))
Sports
High-performance or performance-oriented vehicles designed for speed,
handling, and driving experience.
Economy
Affordable and efficient vehicles focused on practicality, fuel
efficiency, and everyday transportation.
Luxury
Premium vehicles emphasizing comfort, advanced features, high-quality
materials, and brand prestige.
Truck/Utility
Vehicles designed for hauling, towing, cargo transport, or off-road and
utility-focused use.
Other
Manufacturers that do not clearly fit into a single primary vehicle
category.
Niche EV
Specialized or emerging electric vehicle manufacturers with limited
production or unique market focus.
car_counts <- cars |>
count(Model.Year, Electric.Vehicle.Type, Car.Category)
car_plot <-
ggplot(car_counts, aes(x = factor(Model.Year), y = n, fill = Car.Category)) +
geom_bar(stat = "identity",
position = position_dodge(preserve = "single", width = 0.9),
aes(group = Electric.Vehicle.Type, color = Electric.Vehicle.Type), # outline by EV type
linewidth = 0.4) +
scale_fill_brewer(palette = "Set2") + # fill = Car Category
scale_color_manual(
values = c(
"Battery Electric Vehicle (BEV)" = "black",
"Plug-in Hybrid Electric Vehicle (PHEV)" = "red"
),
name = "Vehicle Type" # legend title for outline color
) +
labs(
x = "Model Year",
y = "Number of Vehicles",
title = "BEV vs PHEV by Car Category",
fill = "Car Category"
) +
theme_bw(base_size = 13) +
theme(
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1, face = "bold"),
axis.text.y = element_text(face = "bold"),
axis.title = element_text(face = "bold"),
plot.title = element_text(face = "bold", hjust = 0.5, size = 16),
legend.title = element_text(face = "bold"),
legend.text = element_text(face = "bold")
)
car_plot
ggsave("car_plot.png", plot = car_plot, width = 12, height = 7, dpi = 300)