Electric cars have been increasing in popularity in recent years. Tesla is known as one of the front-runners in electric car sales. Their cars feature more advanced technology compared to those of their competitors. This has attracted many people, including a member of my own family. When looking to purchase a car, it is important to consider its value over its lifetime. Additionally, one should consider the car’s availability across the country.
Data Information
The dataset shows resold Teslas throughout the United States. Each column contains information describing the car and its location, and each row represents a single car. The “year” column contains many N/A values. For entries with a specified year, we assume the car was produced in that year. For entries with N/A values, we assume the cars were produced sometime between 2018 and 2022, since the dataset has not been updated in the past two years.
model: tells which of the Tesla models the car is
year: the year the car was produced
odometer: shows the number of total miles the car has been driven
price: represents the amount the car is now worth
location: tells where the car is being sold
drive_train: explains the type wheel engine power being sent to which wheels
das: tells the extent of the cars’ capabilities to drive itself
accident_history: details about the cars’ past wrecks
paint_job: the color of the cars’ exterior
wheels: the color of rim in the wheel
emi: the excepted monthly payment
zip_code: zip code
interior: the type of interior
state: the state in US the car is currently in
Summary Statics
# A tibble: 6 × 3
Statistic Price Odometer
<chr> <dbl> <dbl>
1 Min. 26500 131
2 1st Qu. 36900 18065
3 Median 43900 28591
4 Mean 45444. 30375.
5 3rd Qu. 52100 38470.
6 Max. 86200 95696
Model 3 Model S Model X Model Y
592 488 235 597
Histogram of Resale Prices
There is a wide range of listings that span a broad range of prices. However, the histogram is left-skewed. In other words, there are more listings priced under $60,000 than over $60,000. The most common listing price is $42,000. For a used car, this is relatively expensive. While cars typically depreciate quickly, this does not seem to be the case for Teslas. Because they are electric and rely on software updates to improve functionality, they tend to retain their value better than other vehicles.
Scatter Plot: Prices Vs Odometer
The more miles a car has, the less it is typically worth. This scatter plot reinforces that trend. However, the line of best fit has a relatively shallow slope, indicating a slow rate of depreciation. The data includes points from all four models in the data set.
Prices Vs Odometer -Model 3 & Model Y
This relationship still shows that the more mileage a car has, the less it is worth. However, this analysis only includes the Model 3 and Model Y.
Box plot: Price Range per State
Car prices can vary by state due to differences in the cost of living. The state with the highest-priced cars is Florida. On average, Florida and Georgia have the highest-priced cars, while Arizona has the lowest prices.
Bar Chart of listings by State
When looking to buy a car, it is important to consider which markets have the most listings available. The top ten states with the most listings are shown in the graph. In the data set, California has the overwhelming majority of Teslas being sold, with just under 800 listings. The state with the next most listings is Maryland, with just over 200.
Price for Each Model
Tesla offers different models at varying price points due to differences in size and amenities. The Model X has the highest average price, at nearly $60,000, followed by the Model S, which averages just over $50,000. The average resale price is an important factor to consider when buying a car, especially if there is a high likelihood of it being resold.
Cars.com Information
To learn more about Teslas being resold, I scraped Cars.com for information on the name, mileage, price, and location. This data specifically pertains to the Model 3 and Model Y. These two models will show the changes in resold Teslas over the past two years.
Average Price per Model
Compared to the average resale value from the original dataset, there has been little change in the resale value of the Model 3 and Model Y. The Model Y was first introduced in 2019, so its resale value is higher due to its relative newness. However, from 2020 to 2022, the value did not change much. Model 3 vehicles produced between 2018 and 2022, and listed within the same years, were originally reselling for around $35,000. However, according to Cars.com, these same cars are now reselling for approximately $25,000. This drop is likely due to the natural depreciation of cars, and there are probably no external factors significantly affecting their worth.
Change in Price by Mileage
The main difference between Cars.com and the original data set is the age of the cars. The newer and older cars on Cars.com have a wider range of mileage compared to the cars listed in the original data set, which includes vehicles from 2018 to 2022. As a result, there are cars with more miles that are priced lower. However, the general trend between mileage and price remains consistent. Over time, Teslas have depreciated, continuing to follow their usual trend.
Source Code
---title: "Final Project BAIS 462" subtitle: "Tesla Information"author: "Kara Carter" toc: true format: html: code-tools: TRUE embed-resources: TRUE execute: warning: FALSE message: FALSE echo: TRUE ---## IntroductionElectric cars have been increasing in popularity in recent years. Tesla is known as one of the front-runners in electric car sales. Their cars feature more advanced technology compared to those of their competitors. This has attracted many people, including a member of my own family. When looking to purchase a car, it is important to consider its value over its lifetime. Additionally, one should consider the car's availability across the country.## Data InformationThe dataset shows resold Teslas throughout the United States. Each column contains information describing the car and its location, and each row represents a single car. The "year" column contains many N/A values. For entries with a specified year, we assume the car was produced in that year. For entries with N/A values, we assume the cars were produced sometime between 2018 and 2022, since the dataset has not been updated in the past two years.**model:** tells which of the Tesla models the car is**year:** the year the car was produced**odometer:** shows the number of total miles the car has been driven**price:** represents the amount the car is now worth**location:** tells where the car is being sold**drive_train:** explains the type wheel engine power being sent to which wheels**das:** tells the extent of the cars' capabilities to drive itself**accident_history:** details about the cars' past wrecks**paint_job:** the color of the cars' exterior**wheels:** the color of rim in the wheel**emi:** the excepted monthly payment**zip_code:** zip code**interior:** the type of interior**state:** the state in US the car is currently in```{r}#| include: false#| label: load packageslibrary(tidyverse) library(jsonlite) library(magrittr) library(httr) library(janitor)library(skimr)library(rvest)library(polite)library(scales)library(readr)``````{r}#| include: false#| label: load and clean dataTesladata <-read_csv ("https://myxavier-my.sharepoint.com/:x:/g/personal/carterk16_xavier_edu/EVFgvgjdtBpGnfxxDVkyBkkBKrTYFL3QIpasRZrnjUU3AQ?download=1",na =c("", "NA", "N/A")) %>%clean_names()# View structureglimpse(Tesladata)# Step 1: Convert data types if neededTesladata <- Tesladata %>%mutate(year =as.integer(year),odometer =as.numeric(odometer),price =as.numeric(price),model =as.factor(model),location =as.factor(location) )Tesladata <- Tesladata %>%distinct()Tesladata <- Tesladata %>%filter(between(price, 10000, 150000)) %>%filter(between(odometer, 0, 150000))Tesladata <- Tesladata %>%filter(!is.na(price), !is.na(odometer), !is.na(model))Tesladata <- Tesladata %>%select(where(~n_distinct(.) >1))glimpse(Tesladata)```## Summary Statics```{r}#| echo: false#| label: Staticsprint_summary_table<-function(Tesladata){price_summary <-summary(Tesladata$price)odometer_summary <-summary(Tesladata$odometer)numeric_summary_tbl <-tibble(Statistic =names(price_summary),Price =as.numeric(price_summary),Odometer =as.numeric(odometer_summary))print(numeric_summary_tbl)}print_summary_table(Tesladata)print(model_summry<-summary(Tesladata$model))```## Histogram of Resale Prices```{r}#| echo: false#| label: Visual 1ggplot(Tesladata, aes(x = price)) +geom_histogram(fill ="#2c3e50", color ="white", bins =30) +labs(title ="Distribution of Tesla Resale Prices",x ="Price (USD)", y ="Number of Listings") +theme_minimal()```There is a wide range of listings that span a broad range of prices. However, the histogram is left-skewed. In other words, there are more listings priced under \$60,000 than over \$60,000. The most common listing price is \$42,000. For a used car, this is relatively expensive. While cars typically depreciate quickly, this does not seem to be the case for Teslas. Because they are electric and rely on software updates to improve functionality, they tend to retain their value better than other vehicles.## Scatter Plot: Prices Vs Odometer```{r}#| echo: false#| label: Visual 2ggplot(Tesladata, aes(x = odometer, y = price)) +geom_point(alpha =0.5, color ="pink1") +geom_smooth(method ="lm", se =FALSE, color ="green4") +labs(title ="Price vs. Odometer Reading",x ="Odometer (miles)", y ="Price (USD)") +theme_minimal()```The more miles a car has, the less it is typically worth. This scatter plot reinforces that trend. However, the line of best fit has a relatively shallow slope, indicating a slow rate of depreciation. The data includes points from all four models in the data set.## Prices Vs Odometer -Model 3 & Model Y```{r}#| echo: false#| label: Visual 6data <- Tesladata %>%filter(str_detect(model, "Model 3|Model Y"))ggplot(data, aes(x = odometer, y = price, color = model)) +geom_point(alpha =0.5) +geom_smooth(method ="lm", se =FALSE) +labs(title ="Price vs. Odometer for Tesla Model 3 and Model Y",x ="Odometer (miles)",y ="Price (USD)",color ="Model" ) +theme_minimal()```This relationship still shows that the more mileage a car has, the less it is worth. However, this analysis only includes the Model 3 and Model Y.## Box plot: Price Range per State```{r}#| echo: false#| label: visual 3 ggplot(Tesladata,aes (x=state, y= price))+geom_boxplot(fill="lightblue", color="darkblue")+labs(title ="Price Range per State",x="State",y="Price")```Car prices can vary by state due to differences in the cost of living. The state with the highest-priced cars is Florida. On average, Florida and Georgia have the highest-priced cars, while Arizona has the lowest prices.## Bar Chart of listings by State```{r}#| echo: false#| label: visual 4 Tesladata %>%count(state, sort =TRUE) %>%top_n(10) %>%ggplot(aes(x =reorder(state, n), y = n)) +geom_col(fill ="purple4") +coord_flip() +labs(title ="Top 10 Locations with Most Resold Teslas",x ="Location", y ="Number of Listings") +theme_minimal()```When looking to buy a car, it is important to consider which markets have the most listings available. The top ten states with the most listings are shown in the graph. In the data set, California has the overwhelming majority of Teslas being sold, with just under 800 listings. The state with the next most listings is Maryland, with just over 200.## Price for Each Model```{r}#| echo: false#| label: Visual 5 avg_price<- Tesladata %>%group_by(model) %>%summarise(avg_price=mean(price))ggplot(avg_price, aes(x=model, y=avg_price))+geom_bar(stat="identity")+labs(title=" Average Price by Model",x="Model",y="Avg Price")```Tesla offers different models at varying price points due to differences in size and amenities. The Model X has the highest average price, at nearly \$60,000, followed by the Model S, which averages just over \$50,000. The average resale price is an important factor to consider when buying a car, especially if there is a high likelihood of it being resold.## Cars.com InformationTo learn more about Teslas being resold, I scraped Cars.com for information on the name, mileage, price, and location. This data specifically pertains to the Model 3 and Model Y. These two models will show the changes in resold Teslas over the past two years.```{r}#| include: false#| label: secondary sourceTesla_second <-read_csv("https://myxavier-my.sharepoint.com/:x:/g/personal/carterk16_xavier_edu/EXI_VIz7tpRNlc4qaund2eUBTuyZSIp89KTqZWmymaUImA?download=1")```## Average Price per Model ```{r}#| echo: false#| label: Secondry Visual 1filtered_data <- Tesla_second %>%group_by(year, make_model) %>%summarize(avg_price =mean(price, na.rm =TRUE), .groups ="drop")# Bar plot for all yearsggplot(filtered_data, aes(x =factor(year), y = avg_price, fill = make_model)) +geom_col(position ="dodge") +labs(title ="Average Tesla Prices by Year and Model",x ="Year",y ="Average Price ($)",fill ="Model" ) +theme_minimal() +scale_fill_brewer(palette ="Set1") +scale_y_continuous(labels = dollar)```Compared to the average resale value from the original dataset, there has been little change in the resale value of the Model 3 and Model Y. The Model Y was first introduced in 2019, so its resale value is higher due to its relative newness. However, from 2020 to 2022, the value did not change much. Model 3 vehicles produced between 2018 and 2022, and listed within the same years, were originally reselling for around \$35,000. However, according to Cars.com, these same cars are now reselling for approximately \$25,000. This drop is likely due to the natural depreciation of cars, and there are probably no external factors significantly affecting their worth.## Change in Price by Mileage```{r}#| echo: false#| label: Secondary visual 2ggplot(Tesla_second, aes(x = miles, y = price, color = make_model)) +geom_point(alpha =0.6, size =2) +geom_smooth(method ="loess", se =FALSE, color ="black") +labs(title ="Price vs Mileage for Used Tesla Models",x ="Mileage",y ="Price ($)",color ="Model" ) +scale_x_continuous(breaks =pretty_breaks(n =6),labels = comma ) +theme_minimal()```The main difference between Cars.com and the original data set is the age of the cars. The newer and older cars on Cars.com have a wider range of mileage compared to the cars listed in the original data set, which includes vehicles from 2018 to 2022. As a result, there are cars with more miles that are priced lower. However, the general trend between mileage and price remains consistent. Over time, Teslas have depreciated, continuing to follow their usual trend.