library(ggplot2)
library(readr)
library(dplyr)
sales_data <- read_csv("ev_vs_gasoline_sales.csv")
ggplot(sales_data, aes(x = Year)) +
geom_line(aes(y = EV_Sales, color = "EV Sales"), size = 2) +
geom_line(aes(y = Gasoline_Sales, color = "Gasoline Sales"), size = 2) +
scale_color_manual(values = c("EV Sales" = "steelblue", "Gasoline Sales" = "darkred")) +
labs(title = "Vehicle Sales: EV vs Gasoline",
x = "Year", y = "Vehicles Sold", color = "Vehicle Type") +
theme_minimal(base_size = 16)sales_data <- sales_data %>%
mutate(EV_Market_Share = round((EV_Sales / (EV_Sales + Gasoline_Sales)) * 100, 1))
ggplot(sales_data, aes(x = Year, y = EV_Market_Share)) +
geom_col(fill = "skyblue", width = 0.6) +
geom_text(aes(label = paste0(EV_Market_Share, "%")), vjust = -0.3, size = 5) +
labs(title = "EV Market Share Over Time", x = "Year", y = "EV Market Share (%)") +
theme_minimal(base_size = 16)## Rows: 2 Columns: 2
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): Fuel_Type
## dbl (1): CO2_Emissions
##
## ℹ 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.
ggplot(co2_data, aes(x = Fuel_Type, y = CO2_Emissions, fill = Fuel_Type)) +
geom_bar(stat = "identity", width = 0.5) +
labs(title = "CO₂ Emissions by Fuel Type", x = "Fuel Type", y = "Emissions (g/km)") +
theme_minimal(base_size = 16) +
theme(legend.position = "none")## Rows: 20 Columns: 2
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): Vehicle_Type
## dbl (1): MPG
##
## ℹ 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.
eff_avg <- efficiency_data %>% group_by(Vehicle_Type) %>% summarise(Average_MPG = round(mean(MPG), 0))
icons <- c("🚗", "🔌")
names(icons) <- c("Gasoline", "Electric")
eff_avg$Icon <- icons[eff_avg$Vehicle_Type]
eff_avg$Repeat <- eff_avg$Average_MPG %/% 10
for (i in 1:nrow(eff_avg)) {
cat(eff_avg$Vehicle_Type[i], " ", strrep(eff_avg$Icon[i], eff_avg$Repeat[i]), " (", eff_avg$Average_MPG[i], " MPG)", "\n")
}## Electric 🔌🔌🔌🔌🔌🔌🔌🔌🔌🔌 ( 101 MPG)
## Gasoline 🚗🚗 ( 25 MPG)
ggplot(efficiency_data, aes(x = MPG, fill = Vehicle_Type)) +
geom_density(alpha = 0.6) +
labs(title = "Fuel Efficiency Distribution", x = "MPG / MPGe", y = "Density") +
theme_minimal(base_size = 16)