-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvehicle sale share.Rmd
124 lines (98 loc) · 4.44 KB
/
vehicle sale share.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
title: "vehicle sale share"
author: "Andrew Dunn"
date: "`r Sys.Date()`"
output: html_document
---
```{r setup}
# data from page 182
# https://tedb.ornl.gov/wp-content/uploads/2021/02/TEDB_Ed_39.pdf#page=182
library(readxl)
library(dplyr)
library(ggplot2)
library(knitr)
library(CPRDataViz)
library(ggrepel)
library(tidyverse)
#setwd("~/Desktop/CPR/electric vehicle tax credits Nov 2022")
# Prior data
full_df <- read_excel("Hybrid and Plug-In Vehicle Sales.xlsx")
df <- full_df %>%
select(1, 6:8) %>%
rename("Year" = "Calendar year", "Hybrid" = "Hybrid share of all light vehicles",
"Plugin" = "Plug-in hybrid share of all light vehicles",
"Electric" = "All-electric share of all light vehicles")
# Old data projections from:
# https://www.alternativasostenibile.it/sites/default/files/BCG-The-Electric-Car-Tipping-Point-Jan-2018_tcm9-180862.pdf
# Data projections from Exhibit 1:
# https://www.bcg.com/publications/2022/electric-cars-finding-next-gear
# showing the math
battery_2025 = .19
hybrid_2025 = .10 + .14
plugin_2025 = .04
battery_2030 = .47
hybrid_2030 = .25 + .09
plugin_2030 = .06
battery_2035 = .68
hybrid_2035 = .21 + .06
plugin_2035 = .04
# add the rows
df[nrow(df) + 1,] = list(2025, hybrid_2025, plugin_2025, battery_2025)
df[nrow(df) + 1,] = list(2030, hybrid_2030, plugin_2030, battery_2030)
df[nrow(df) + 1,] = list(2035, hybrid_2035, plugin_2035, battery_2035)
# Zai Rutter ~ adding final points per Mehul's Request
#data_ends <- pivot_longer(cols = !Year, names_to = "type", values_to = "value",df)
data_ends <- df %>% filter(Year == 2035)
data_ends <- pivot_longer(cols = !Year, names_to = "type", values_to = "value",data_ends)
```
```{r graph, echo=FALSE}
ggplot(df, aes(x = Year, Hybrid)) +
#theme_cpr() +
# Data lines
geom_line(aes(y = Hybrid), color = "darkred") +
geom_text(data = df %>% filter(Year == last(Year)), aes(label = "Hybrid",
x = Year + 1.2,
y = Hybrid) , size = 3) +
geom_line(aes(y = Plugin), color = "steelblue") +
geom_text(data = df %>% filter(Year == last(Year)), aes(label = "Plug-in",
x = Year + 1.2,
y = Plugin) , size = 3) +
geom_line(aes(y = Electric), color = "darkgreen") +
geom_text(data = df %>% filter(Year == last(Year)), aes(label = "Electric",
x = Year + 1.2,
y = Electric) , size = 3) +
scale_y_continuous(labels = scales::percent_format(accuracy = 1), limits = c(0, .7)) +
scale_x_continuous(limits = c(2010, 2037), breaks = seq(2010, 2035, 5)) +
# The vertical line
geom_segment(aes(x = 2022, y = 0, xend = 2022, yend = .65), linetype="dotted", color = "black", size= .5) +
annotate("text", x = 2024.5, y = .53, label = "Inflation Reduction \n Act passed in 2022", size = 3) +
# Labels and whole graph formatting
labs(x = "Year",
y = "Share of All Light Vehicles",
title = "Electric Vehicle Sales are Projected to Grow Rapidly in the Future",
subtitle = "Historic and Projected Clean Vehicle Adoption Rates (2010-35)",
caption = c("\n Sources: Transportation Energy Book Data Book, Edition 39 (2021) \n
Electric Cars Are Finding Their Next Gear (2022) \n
Author: Andrew Dunn \n
Editor: Zai Rutter \n
Date: Nov 29, 2022"),
color = 'Committees') +
theme(plot.caption = element_text(lineheight = 0.5, size = 7),
plot.caption.position = "plot",
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5, size = 9),
axis.title = element_text(size = 9),
panel.grid.minor = element_blank(),
panel.grid.major.y = element_blank(),
panel.background = element_blank())
# Zai Rutter adding final data points per request
#geom_text_repel(
# aes(label = value), data = data_ends,
# fontface ="plain", color = "black", size = 3
#)
#scale_y_continuous(sec.axis = sec_axis(~ ., breaks = data_ends$value))
#Now he wants mid marks instead..
# save the graph
ggsave("clean_vehicle_graph.png")
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.