The data set selected for this work shop was the population of electric vehicles in Washington State
EVP <- read.csv("C:/Users/Ozili Nwokobia/Downloads/Electric_Vehicle_Population_Data.csv", header=FALSE, stringsAsFactors=TRUE)
View(EVP)
Question 1: Will battery electric vehicles be more popular compared to hybrid plug-in because fully electric cars have the reputation of being more eco-friendly?
library(ggplot2)
ev_type_counts <- as.data.frame(table(EVP$V9))
View(ev_type_counts)
colnames(ev_type_counts) <- c("Type", "Count")
pie_chart <- ggplot(ev_type_counts, aes(x = "", y = Count, fill = Type)) +
geom_bar(width = 1, stat = "identity") +
coord_polar("y", start = 0) +
theme_void() +
labs(title = "Distribution of Electric Vehicle Types") +
scale_fill_brewer(palette = "Set3")
print(pie_chart)
Question 2: Will Tesla have the most electric cars on the road since their entire vehicle line up is only electric vehicles and they’re the most popular brand of electric cars?
library(viridis)
## Warning: package 'viridis' was built under R version 4.3.3
## Loading required package: viridisLite
make_counts <- as.data.frame(table(EVP$V7))
colnames(make_counts) <- c("Make", "Count")
pie_chart_make <- ggplot(make_counts, aes(x = "", y = Count, fill = Make)) +
geom_bar(width = 1, stat = "identity") +
coord_polar("y", start = 0) +
theme_void() +
labs(title = "Distribution of Electric Vehicle Makes") +
scale_fill_viridis(discrete = TRUE, option = "D")
print(pie_chart_make)
line_graph <- ggplot(make_counts, aes(x = Make, y = Count, group = 1)) +
geom_line(aes(color = Make)) +
geom_point(aes(color = Make)) +
theme_minimal() +
labs(title = "Count of Electric Vehicles by Make",
x = "Vehicle Make",
y = "Count") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_color_viridis_d(option = "D", guide = FALSE)
print(line_graph)
## Warning: The `guide` argument in `scale_*()` cannot be `FALSE`. This was deprecated in
## ggplot2 3.3.4.
## ℹ Please use "none" instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Question 3: Will Seattle have the most electric Vehicles because they have the largest population in Washington State?
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
city_counts <- as.data.frame(table(EVP$V3))
colnames(city_counts) <- c("City", "Count")
top_cities <- city_counts %>%
arrange(desc(Count)) %>%
head(10)
bar_graph_city <- ggplot(top_cities, aes(x = reorder(City, -Count), y = Count, fill = City)) +
geom_bar(stat = "identity") +
theme_minimal() +
labs(title = "Top 10 Cities with Electric Cars",
x = "City",
y = "Count") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_fill_viridis_d(option = "D", guide = FALSE)
print(bar_graph_city)