Created
January 12, 2023 16:41
-
-
Save benmarwick/be0a98163192d320271ab8655c1000ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rvest) | |
library(tidyverse) | |
library(lubridate) | |
# https://bringatrailer.com/electric-vehicles/?search=rivian | |
# from 11 Jan 2023 | |
url <- "~/Downloads/bat.html" | |
price_date <- | |
url %>% | |
read_html() %>% | |
html_elements(" .subtitle") %>% | |
html_text() | |
model <- | |
url %>% | |
read_html() %>% | |
html_elements(".overlayable a ") %>% | |
html_text() | |
model <- model[model != "\n "] | |
price_date_model_tbl <- | |
tibble(price_date, | |
model) %>% | |
separate(price_date, | |
c("price", "date"), | |
"on") %>% | |
mutate( | |
sold_bid = case_when( | |
str_detect(price_date, "Sold") ~ "Sold", | |
str_detect(price_date, "Bid") ~ "Bid" | |
), | |
price = parse_number(price), | |
date = mdy(str_squish(date)), | |
spec = case_when( | |
str_detect(model, "Adventure") ~ "Adventure", | |
str_detect(model, "Launch") ~ "Launch" | |
), | |
model = case_when( | |
str_detect(model, "R1T") ~ "R1T", | |
str_detect(model, "R1S") ~ "R1S" | |
)) %>% | |
drop_na() | |
price_date_model_tbl %>% | |
filter(sold_bid == "Sold") %>% | |
ggplot() + | |
aes(date, | |
price, | |
colour = model, | |
group = model) + | |
geom_point(size = 4) + | |
theme_minimal() + | |
scale_x_date(date_labels = "%m/%Y") + | |
scale_y_continuous(labels = scales::dollar) + | |
ggtitle("Rivian sale prices from bringatrailer.com") + | |
geom_smooth(method = "lm", | |
fullrange = TRUE) + | |
ylim(limits = c(0, 130000)) + | |
xlim(c(mdy("1/1/22"), mdy("1/1/26"))) |
Author
benmarwick
commented
Jan 12, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment