An electric vehicle (EV) is a vehicle that uses one or more electric motors for propulsion. It can be powered by a collector system, with electricity from extravehicular sources, or it can be powered autonomously by a battery (sometimes charged by solar panels, or by converting fuel to electricity using fuel cells or a generator (Often known as a hybrid)). EVs include but are not limited to road and rail vehicles, and broadly can also include electric boat and underwater vessels (submersibles, and technically also diesel- and turbo-electric submarines), electric aircraft and electric spacecraft.
Data was taken from kaggle
library(tidyr)
library(ggplot2)
car <- read.csv("data_input/us_car_data.csv")
head(car)
From inspecting the data above, we knew there was 17 columns.
All the columns are:
First we will remove some columns that we don’t use
car_clean <- subset(car, select = -c(4, 9, 10, 11, 12, 13, 14, 15, 16, 17))
head(car_clean)
Next we will check is there any missing value on the dataset
colSums(is.na(car_clean))
## County City State
## 0 0 0
## Model.Year Make Model
## 0 0 0
## Electric.Vehicle.Type
## 0
There’s no missing value in the data. Data is ready to be analyzed and visualized
str(car_clean)
## 'data.frame': 134474 obs. of 7 variables:
## $ County : chr "Thurston" "Island" "Snohomish" "King" ...
## $ City : chr "Tumwater" "Clinton" "Snohomish" "Seattle" ...
## $ State : chr "WA" "WA" "WA" "WA" ...
## $ Model.Year : int 2019 2022 2020 2020 2013 2018 2020 2021 2019 2018 ...
## $ Make : chr "TESLA" "NISSAN" "TESLA" "TESLA" ...
## $ Model : chr "MODEL 3" "LEAF" "MODEL 3" "MODEL 3" ...
## $ Electric.Vehicle.Type: chr "Battery Electric Vehicle " "Battery Electric Vehicle " "Battery Electric Vehicle " "Battery Electric Vehicle " ...
From str function above, some data types are not in the right type. Therefore we should change them into the correct one.
car_clean$County <- as.factor(car_clean$County)
car_clean$City <- as.factor(car_clean$City)
car_clean$State <- as.factor(car_clean$State)
car_clean$Make <- as.factor(car_clean$Make)
car_clean$Electric.Vehicle.Type <- as.factor(car_clean$Electric.Vehicle.Type)
str(car_clean)
## 'data.frame': 134474 obs. of 7 variables:
## $ County : Factor w/ 39 levels "Adams","Asotin",..: 34 15 31 17 31 4 31 31 34 34 ...
## $ City : Factor w/ 454 levels "Aberdeen","Acme",..: 412 72 369 351 112 221 227 112 279 191 ...
## $ State : Factor w/ 1 level "WA": 1 1 1 1 1 1 1 1 1 1 ...
## $ Model.Year : int 2019 2022 2020 2020 2013 2018 2020 2021 2019 2018 ...
## $ Make : Factor w/ 36 levels "AUDI","AZURE DYNAMICS",..: 31 25 31 31 31 4 31 1 33 25 ...
## $ Model : chr "MODEL 3" "LEAF" "MODEL 3" "MODEL 3" ...
## $ Electric.Vehicle.Type: Factor w/ 2 levels "Battery Electric Vehicle ",..: 1 1 1 1 1 2 1 2 2 1 ...
Data type is changed
summary(car_clean$Model.Year)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1997 2018 2021 2020 2022 2024
From the summary above, we knew that most electric vehicle model is from 2020 with the oldest model from year 1997 and the latest model comes from year 2024.
hist(car_clean$Model.Year)
From the histogram above we could see the majority of electric vehicle model used in US comes from year 2020is model.
Next we will check the passenger ticket class distribution
sort(table(car_clean$Make), decreasing = T)
##
## TESLA NISSAN CHEVROLET
## 61650 13138 11417
## FORD BMW KIA
## 6876 5881 5484
## TOYOTA VOLKSWAGEN VOLVO
## 4857 3518 2965
## AUDI JEEP HYUNDAI
## 2720 2608 2390
## CHRYSLER RIVIAN PORSCHE
## 2222 1805 951
## FIAT HONDA MERCEDES-BENZ
## 807 786 777
## MITSUBISHI MINI POLESTAR
## 747 742 657
## SMART SUBARU JAGUAR
## 277 272 222
## LINCOLN LUCID CADILLAC
## 211 141 119
## LEXUS GENESIS LAND ROVER
## 80 67 42
## FISKER MAZDA AZURE DYNAMICS
## 15 12 8
## TH!NK BENTLEY WHEEGO ELECTRIC CARS
## 4 3 3
From the summary above we could see the most popular electric vehicle used comes from Tesla by 61650 cars and the least used comes from Bentley and Wheego Electric Cars.
We will make a plot to which we could see top 10 model from our dataset. We will need to create a new dataframe with frequency on it
freq <- as.data.frame(table(car_clean$Model))
freq <- freq[order(freq$Freq, decreasing = T), ]
freq <- head(freq, 10)
Next we create the plot using bar plot
ggplot(data = freq, mapping = aes(x = reorder(Var1, Freq), y = Freq)) +
geom_col(fill = "lightblue") +
geom_text(aes(label = Freq)) +
coord_flip() +
labs(x = "Electric Vehicle Manufacturer",
y = "Frequency",
title = "Top 10 US Electric Vehicle Model",
subtitle = "Year of 1997 to 2024")
From plot above we could see that the most popular electric vehicle model used is Model 3 by 25752 units.
Next we will see how much units does top 3 manufacturer make each year. To do that we need to create a new data frame.
top3 <- car_clean[car_clean$Make %in% c("TESLA", "NISSAN", "CHEVROLET"), ]
top3 <- droplevels(top3)
freq_top3 <- as.data.frame(table(top3$Model.Year, top3$Make))
Next we will create the plot using line plot.
ggplot(data = freq_top3, mapping = aes(x = Var1, y = Freq, group = 1))+
geom_line(mapping = aes(group = Var2, color = Var2)) +
geom_point(col = "black") +
labs(x = "Year",
y = "Frequency",
title = "Top 3 Manufacturer Total Electric Vehicle Production",
subtitle = "Year of 1997 to 2024",
color = "Manufacturer")
Based on the plot above, we know year 2022 is Tesla’s peak production have from 1997 until 2024. Also there’s not much different in production quantity between Chevrolet and Nissan