Introduction to Dataset

The dataset used for this analysis contains information about electric vehicles registered in Washington State specifically in 2023. The original dataset contains 138,779 observations and 17 variables. These variables include both categorical and numerical information, such as vehicle make, model, model year, electric vehicle type, county, and electric range. Before creating the visualizations, I examined the structure of the dataset and noticed that it included a few records from states other than Washington. To keep the analysis focused on Washington, I filtered the dataset to only include records where the state was listed as WA. After exploring the data, I focused on identifying patterns in electric vehicles based on vehicle type, manufacturer, model year, and county. The dataset includes a wide range of model years which allowed me to look for comparisons between older and newer electric vehicles. I also examined the different types of electric vehicles and found that the dataset includes both Battery Electric Vehicles (BEVs) and Plug-in Hybrid Electric Vehicles (PHEVs). These variables were used to create visualizations that show how electric vehicles are distributed across different manufacturers, years, counties, and vehicle types.

Findings

Electric Vehicles by Type

library(data.table)
filename <- "EV_Population_Data.csv"
df <- fread(filename)

library(dplyr)

df <- df[df$State == "WA"]


MakeEVCount <- data.frame(count(df, Make))
MakeEVCount <- MakeEVCount[order(MakeEVCount$n, decreasing = TRUE),]
rownames(MakeEVCount) <- c(1:nrow(MakeEVCount))

library(ggplot2)

df$`Electric Vehicle Type` <- ifelse(df$`Electric Vehicle Type` == "Battery Electric Vehicle (BEV)", "BEV", "PHEV")

library(ggplot2)
library(lubridate)
library(dplyr)
library(scales)
library(ggthemes)
library(RColorBrewer)
library(ggrepel)

library(plotly)
EVTypeDonut_df <- df %>%
  select(`Electric Vehicle Type`) %>%
  group_by(`Electric Vehicle Type`) %>%
  summarise(n= length(`Electric Vehicle Type`), .groups = 'keep') %>%
  data.frame()

EVTypeDonut_df %>%
  plot_ly(., labels = ~Electric.Vehicle.Type, values = ~n) %>%
  add_pie(hole = 0.6) %>%
  layout(title = list(text = "Electric Vehicles by Type (Plug-in Hybrid EV or Battery EV)", x=0.02, y = 0.98)) %>%
  layout(annotations=list(text=paste0("Total Electric Vehicle Count: \n", 
                          scales::comma(sum(EVTypeDonut_df$n))),
                          "showarrow"=F))

This visualization is a donut chart showing the overall breakdown of electric vehicles by their type (whether they are a Plug-in Hybrid EV or a Battery EV) and shows the proportion of each type within the entire dataset. The center of the donut also shows the total number of electric vehicles included in the analysis. From this visualization you can see that majority of the electric vehicles in Washington are battery electric vehicles.

Electric Vehicles by County

CountyEVCount <- df %>%
  select(County) %>%
  group_by(County) %>%
  summarise(n=length(County), .groups = 'keep') %>%
  data.frame()

CountyEVCount <- CountyEVCount[order(CountyEVCount$n, decreasing = TRUE),]
rownames(CountyEVCount) <- c(1:nrow(CountyEVCount))

top_CountyEV <- CountyEVCount[1:10, ]

otherCounty_df <- df %>%
  filter(!County %in% top_CountyEV$County) %>%
  select(County) %>%
  mutate(County = "Other") %>%
  group_by(County) %>%
  summarise(n = length(County), .groups = 'keep') %>%
  data.frame()


County_df <- rbind(top_CountyEV, otherCounty_df)


County_df <- County_df %>%
  select(County, n) %>%
  mutate(percent_of_total = round(100*n/sum(n),1)) %>%
  data.frame()

County_df$County <- factor(County_df$County, levels = County_df$County[order(County_df$n, decreasing = TRUE)])

ggplot(data = County_df, aes(x="", y=n, fill = County)) +
  geom_bar(stat="identity", position="fill") +
  coord_polar(theta="y", start=0) +
  labs(fill = "Top Counties", x = NULL, y = NULL, 
       title = "Electric Vehicles in Washington State by County (2023)",
       caption = "Slices under 2% are not labeled") +
  theme_light() +
  theme(plot.title = element_text(hjust = 0.5),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        panel.grid = element_blank()) +
  scale_fill_brewer(palette= "Set3") +
  geom_text(aes(x=1.6, label=ifelse(percent_of_total>2,paste0(percent_of_total,"%"),"")),
            size=4,
            position=position_fill(vjust=0.5))

This visualization is a pie chart which shows the percentage of electric vehicles located in the top 10 counties compared with the 29 remaining counties in the dataset, which are grouped into an “Other” category. This allows the distribution of electric vehicles across Washington to be viewed as a percentage of the total rather than just as a count. The visualization shows that over half of Washington’s electric vehicles are concentrated in King county.

Top 10 Counties by Electric Vehicle Count and Type

County_EVType_df <- df %>%
  select(County, `Electric Vehicle Type`) %>%
  group_by(County, `Electric Vehicle Type`) %>%
  summarise(n = length(`Electric Vehicle Type`), .groups = 'keep') %>%
  data.frame()
Top10_Counties <- County_EVType_df %>%
  group_by(County) %>%
  summarise(Total_EV = sum(n)) %>%
  arrange(desc(Total_EV))
Top10_Counties <- Top10_Counties[1:10, ]

County_EVType_df <- County_EVType_df %>%
  filter(County %in% Top10_Counties$County) 

County_EVType_df$County <- factor(County_EVType_df$County,levels = Top10_Counties$County)

ggplot(County_EVType_df, aes(x = County,  y = n, fill = Electric.Vehicle.Type )) +
  geom_bar(stat="identity", position="dodge") +
  theme_light()+
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(labels = comma) +
  labs(title = "Multiple Bar Chart - Top 10 Counties by Electric Vehicle Count and Type",
       x = "Counties",
       y = "EV Count",
       fill = "EV Type") +
  scale_fill_brewer(palette = "Set2") +
  facet_wrap(~Electric.Vehicle.Type)

After creating the pie chart I decided that I wanted to compare the different electric vehicle types within each county by using a multiple car chart. From this visualization you can see King and Snohomish, as well as the rest of the counties, have considerably more battery electric vehicles.

Electric Vehicle Count by Model Year and Type

EVType_df <- df %>% 
  filter(`Model Year` >= 2010 & `Model Year` <= 2023) %>%
  select(`Model Year`,`Electric Vehicle Type`) %>%
  group_by(`Model Year`, `Electric Vehicle Type`) %>%
  summarise(n= length(`Electric Vehicle Type`), .groups = 'keep') %>%
  data.frame()

ggplot(EVType_df, aes(x = Model.Year, y = n, group = Electric.Vehicle.Type)) +
  geom_line(aes(color=Electric.Vehicle.Type), linewidth=3) +
  labs(title = "Electric Vehicle Count by Model Year and by Type", x = "Vehicle Model Year", y = "EV Count") +
  theme_light() +
  theme(plot.title = element_text(hjust=0.5)) +
  geom_point(shape=21, size=5, color="black", fill="white") +
  scale_y_continuous(labels=comma) +
  scale_x_continuous(breaks = seq(min(EVType_df$Model.Year), max(EVType_df$Model.Year), 1)) +
  scale_color_brewer(palette = "Set2", name = "EV Type")

This is a line chart showing the number of electric vehicles by model year and vehicle type. The dataset has model year information from 1997 to 2024, but for this specific visualization I decided to focus on years 2010 through 2023 to show when electric vehicles became more common. The two lines represent battery electric vehicles and plug-in hybrid electric vehicles, showing the growth of each type over time. The chart shows that battery electric vehicles generally having higher counts than plug-hybrid electric vehicles.

Electric Vehicle Count by Manufacturer

top_MakeEV <- MakeEVCount$Make[1:10]

new_df <- df %>% 
  filter(Make %in% top_MakeEV) %>%
  select(Make,`Electric Vehicle Type`) %>%
  group_by(Make, `Electric Vehicle Type`) %>%
  summarise(n= length(`Electric Vehicle Type`), .groups = 'keep') %>%
  data.frame()

other_df <- df %>%
  filter(!Make %in% top_MakeEV) %>%
  select(`Electric Vehicle Type`) %>%
  mutate(Make = "Other") %>%
  group_by(Make, `Electric Vehicle Type`) %>%
  summarise(n = length(`Electric Vehicle Type`), .groups = 'keep') %>%
  data.frame()


new_df <- rbind(new_df, other_df)

agg_tot <- new_df %>%
  select(Make, n) %>%
  group_by(Make) %>%
  summarise(tot = sum(n), .groups = 'keep') %>%
  data.frame()

library(ggplot2)
library(scales)
library(RColorBrewer)
library(ggthemes)
library(plyr)

max_y <- round_any(max(agg_tot$tot), 25000, ceiling)
ggplot(new_df, aes(x = reorder(Make, n, sum), y = n, fill = Electric.Vehicle.Type)) + 
  geom_bar(stat="identity") +
  coord_flip() +
  labs(title = "Electric Vehicle Count by Manufacturer", x = "", y = "EV Count", fill = "EV Type") +
  theme_light() +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_brewer(palette="Set2") +
  geom_text(data = agg_tot, aes(x = Make, y = tot, label = scales::comma(tot), fill = NULL), hjust = -0.1, size = 4) +
  scale_y_continuous(labels = comma,
                     breaks = seq(0, max_y, 5000),
                     limits=c(0, max_y))

This chart shows the number of electric vehicles by manufacturer. I focused on the top 10 manufacturers and separated the vehicles by electric vehicle type. This graph makes it easier to compare which manufacturers have the largest number of electric vehicles in Washington and whether their vehicles are primarily battery electric vehicles or plug-in hybrid electric vehicles. The chart shows that Tesla has a much larger presence in the Washington electric vehicle market than other manufacturers and a huge presence specifically in the battery electric vehicle market.