Load Libraries and Excel Data
# Load Required Libraries
library(dplyr)
library(ggplot2)
library(tidyr)
library(readxl)
# Load Excel Data
Apple_Inc <- read_excel("~/Downloads/Apple Inc NasdaqGS AAPL Financials (1).xls")
Preview of data
head(Apple_Inc)
## # A tibble: 6 Ć 9
## Apple Inc. (NasdaqGS:AAPL) >ā¦Ā¹ ...2 ...3 ...4 ...5 ...6 ...7 ...8 ...9
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 2 In Millions of the trading cu⦠Curr⦠Trad⦠ Conv⦠Toda⦠<NA> <NA> <NA>
## 3 <NA> Orde⦠Late⦠ Unit⦠S&P ⦠<NA> <NA> <NA>
## 4 <NA> Deci⦠Capi⦠ Dilu⦠Basic <NA> <NA> <NA>
## 5 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 6 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## # ā¹ abbreviated name: ¹ā`Apple Inc. (NasdaqGS:AAPL) > Financials > Key Stats`
Print Financial Summary
# Print the financial summary to review the data
print(financial_summary)
## Metric TTM.Q3.20 TTM.Q3.21 TTM.Q3.22 TTM.Q3.23
## 1 Total Revenue 274515 365817 394328 383285
## 2 Gross Profit 104956 152836 170782 169148
## 3 EBITDA 77344 120233 130541 125820
Create a Line Plot for Profitability Data
# Reshape the data using pivot_longer for easy plotting with ggplot2
financial_long <- financial_summary %>%
pivot_longer(cols = starts_with("TTM"), names_to = "Year", values_to = "Amount")
# Create a Line Plot showing the trend over time
ggplot(financial_long, aes(x = Year, y = Amount, color = Metric, group = Metric)) +
geom_point() + # Add points to mark the actual data
geom_line() + # Add lines connecting the point
theme_minimal() + # Use a clean, minimal theme
labs(title = "Apple's Financial Performance (2020-2024)", x = "Year", y = "Amount ($ in millions)") +
scale_y_continuous(labels = scales::comma) # Format y-axis with commas for readability
