getwd()[1] "/Users/zwang30/Downloads"
getwd()[1] "/Users/zwang30/Downloads"
library(readr)
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.
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(ggplot2)
head(electric_vehicle_data)# A tibble: 6 × 17
`VIN (1-10)` County City State `Postal Code` `Model Year` Make Model
<chr> <chr> <chr> <chr> <dbl> <dbl> <chr> <chr>
1 2C4RC1N71H Kitsap Bremerton WA 98311 2017 CHRY… PACI…
2 2C4RC1N7XL Stevens Colville WA 99114 2020 CHRY… PACI…
3 KNDC3DLCXN Yakima Yakima WA 98908 2022 KIA EV6
4 5YJ3E1EA0J Kitsap Bainbridge… WA 98110 2018 TESLA MODE…
5 1N4AZ1CP7J Thurston Tumwater WA 98501 2018 NISS… LEAF
6 KNDCC3LG6K Kitsap Port Orcha… WA 98367 2019 KIA NIRO
# ℹ 9 more variables: `Electric Vehicle Type` <chr>,
# `Clean Alternative Fuel Vehicle (CAFV) Eligibility` <chr>,
# `Electric Range` <dbl>, `Base MSRP` <dbl>, `Legislative District` <dbl>,
# `DOL Vehicle ID` <dbl>, `Vehicle Location` <chr>, `Electric Utility` <chr>,
# `2020 Census Tract` <chr>
summary(electric_vehicle_data) VIN (1-10) County City State
Length:159467 Length:159467 Length:159467 Length:159467
Class :character Class :character Class :character Class :character
Mode :character Mode :character Mode :character Mode :character
Postal Code Model Year Make Model
Min. : 1730 Min. :1997 Length:159467 Length:159467
1st Qu.:98052 1st Qu.:2018 Class :character Class :character
Median :98122 Median :2021 Mode :character Mode :character
Mean :98170 Mean :2020
3rd Qu.:98370 3rd Qu.:2023
Max. :99577 Max. :2024
NA's :4
Electric Vehicle Type Clean Alternative Fuel Vehicle (CAFV) Eligibility
Length:159467 Length:159467
Class :character Class :character
Mode :character Mode :character
Electric Range Base MSRP Legislative District DOL Vehicle ID
Min. : 0.00 Min. : 0 Min. : 1.00 Min. : 4385
1st Qu.: 0.00 1st Qu.: 0 1st Qu.:18.00 1st Qu.:173101620
Median : 14.00 Median : 0 Median :33.00 Median :219844964
Mean : 64.28 Mean : 1228 Mean :29.26 Mean :214024243
3rd Qu.: 84.00 3rd Qu.: 0 3rd Qu.:43.00 3rd Qu.:244836346
Max. :337.00 Max. :845000 Max. :49.00 Max. :479254772
NA's :361
Vehicle Location Electric Utility 2020 Census Tract
Length:159467 Length:159467 Length:159467
Class :character Class :character Class :character
Mode :character Mode :character Mode :character
colnames(electric_vehicle_data) [1] "VIN (1-10)"
[2] "County"
[3] "City"
[4] "State"
[5] "Postal Code"
[6] "Model Year"
[7] "Make"
[8] "Model"
[9] "Electric Vehicle Type"
[10] "Clean Alternative Fuel Vehicle (CAFV) Eligibility"
[11] "Electric Range"
[12] "Base MSRP"
[13] "Legislative District"
[14] "DOL Vehicle ID"
[15] "Vehicle Location"
[16] "Electric Utility"
[17] "2020 Census Tract"
recent_evs <- electric_vehicle_data %>%
filter(`Model Year` >= 2015) %>%
mutate(`Model Year` = as.numeric(`Model Year`),
`Electric Range` = as.numeric(`Electric Range`)) %>%
group_by(Make) %>%
filter(n() > 200) ggplot(recent_evs, aes(x = `Model Year`, y = `Electric Range`, color = Make)) +
geom_jitter(alpha = 0.5, width = 0.2, height = 0) +
facet_wrap(~Make, scales = "free_y") +
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))