library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate)
library(readxl)
library(dplyr)
library(ggplot2)
library(lubridate)

# Read data and correctly parse the date
daily_oil_prices <- read_excel("Export.xlsx") |>
  mutate(Date = dmy(Date)) |>
  rename(Price = `Crude Oil Price`) |> 
  mutate(Price = as.numeric(Price)) |>
  arrange(Date)

# Plot
daily_oil_prices |> 
  ggplot(aes(x = Date, y = Price)) +
  geom_line(color = "darkgreen") +
  geom_smooth(method = "loess", color = "blue", se = FALSE) +
  labs(title = "Daily Crude Oil Prices",
       x = "Date",
       y = "Price (USD)") +
  theme_minimal()
`geom_smooth()` using formula = 'y ~ x'

library(readxl)
library(dplyr)
library(lubridate)
library(ggplot2)

# Read data and correctly parse the date
yearly_oil_prices <- daily_oil_prices |>
  mutate(Year = floor_date(Date, "year")) |>
  group_by(Year) |>
  summarise(Avg_Price = mean(Price, na.rm = TRUE))

# Plot monthly average prices
yearly_oil_prices |> 
  ggplot(aes(x = Year, y = Avg_Price)) +
  geom_line(color = "blue", size = 1) +
  geom_point(color = "darkblue", size = 2) +
  labs(title = "Yearly Average Crude Oil Prices",
       x = "Year",
       y = "Average Price (USD)") +
  theme_minimal()
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.