#Tesla Stock change when Elon bought twitter

# Load necessary packages
library(tidyquant)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## ── Attaching core tidyquant packages ─────────────────────── tidyquant 1.0.11 ──
## ✔ PerformanceAnalytics 2.0.8      ✔ TTR                  0.24.4
## ✔ quantmod             0.4.26     ✔ xts                  0.14.1
## ── Conflicts ────────────────────────────────────────── tidyquant_conflicts() ──
## ✖ zoo::as.Date()                 masks base::as.Date()
## ✖ zoo::as.Date.numeric()         masks base::as.Date.numeric()
## ✖ PerformanceAnalytics::legend() masks graphics::legend()
## ✖ quantmod::summary()            masks base::summary()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)

# Set stock symbol and date range
symbol <- "TSLA"
start_date <- "2022-01-01"
end_date <- "2022-12-31"

# Get Tesla stock price data
tsla_data <- tq_get(symbol, from = start_date, to = end_date)

# Plot the stock price with key event markers
ggplot(tsla_data, aes(x = date, y = adjusted)) +
  geom_line(color = "blue", size = 1) +  # Stock price line
  geom_vline(xintercept = as.Date("2022-04-14"), linetype = "dashed", color = "red") +  # April 14 (Musk's offer)
  geom_vline(xintercept = as.Date("2022-10-27"), linetype = "dashed", color = "red") +  # October 27 (Acquisition completed)
  labs(title = "2022 Tesla Stock Price Around Elon Musk's Twitter Acquisition",
       x = "Date",
       y = "Adjusted Closing Price") +
  scale_x_date(date_breaks = "1 month", date_labels = "%b") +  # Ensures Nov is included
  theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.