Q1. manipulating data, medians

data(cars)

median(cars$speed)
## [1] 15

Q.2 URL manipulation and extracting values from url based datasets

# install.packages("jsonlite")
library(jsonlite)

url <- ("https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=100")
json_data <- fromJSON(url)

btc_data <- json_data$Data$Data

max_close <- max(btc_data$close, na.rm = TRUE)

max_close
## [1] 96945.09

Q.3 The Ultimate Decline of Luxury Fahsion Sales

# install.packages(c("tidyverse", "knitr"))
library(tidyverse)
library(ggplot2)
url <- ("https://www.mckinsey.com/~/media/mckinsey/industries/retail/our%20insights/state%20of%20fashion/2025/the-state-of-fashion-2025-v2.pdf")
# q.1 Data from the McKinsey report (projected % change in luxury sales for 2025).

luxury_growth_2025 <- tibble(
  Region = c("China", "Europe", "US"),
  Growth_Low  = c(-3, 1, 2),
  Growth_High = c(0,  3, 4)
) %>%
  mutate(Average_Growth = (Growth_Low + Growth_High) / 2)

luxury_growth_2025
## # A tibble: 3 × 4
##   Region Growth_Low Growth_High Average_Growth
##   <chr>       <dbl>       <dbl>          <dbl>
## 1 China          -3           0           -1.5
## 2 Europe          1           3            2  
## 3 US              2           4            3
ggplot(luxury_growth_2025, aes(x = Region, y = Average_Growth, fill = Region)) +
  geom_col() +
  geom_text(aes(label = paste0(Average_Growth, "%")), vjust = -0.5, size = 4) +
  labs(title = "Projected Luxury Sales Growth in 2025",
       y = "Average Growth (%)",
       x = NULL) +
  theme_minimal() +
  scale_fill_brewer(palette = "Set2") +
  theme(legend.position = "none")

# q.2 Economic profit (a measure of how much money luxury companies really make) dropped in 2024

profit_data <- tibble(
  Year = c("2023", "2024"),
  Profit_Change = c(0, -1)          
)

profit_data
## # A tibble: 2 × 2
##   Year  Profit_Change
##   <chr>         <dbl>
## 1 2023              0
## 2 2024             -1
#q.3 Key numbers from the report that explain why people are buying less luxury

reasons <- tibble(
  Reason = c("US shoppers trading down", 
             "China prefers local brands", 
             "Negative feelings about luxury in China", 
             "Chinese tourists spending less in Europe"),
  Value = c(64, 35, -18, 59),
  Note = c("% of US shoppers", "% point increase", "net sentiment %", "% of 2019 levels")
)

reasons
## # A tibble: 4 × 3
##   Reason                                   Value Note            
##   <chr>                                    <dbl> <chr>           
## 1 US shoppers trading down                    64 % of US shoppers
## 2 China prefers local brands                  35 % point increase
## 3 Negative feelings about luxury in China    -18 net sentiment % 
## 4 Chinese tourists spending less in Europe    59 % of 2019 levels
# Luxury fashion sales are slowing because:
## China, biggest market, is flat or shrinking
## Profits are falling for many luxury companies
## Shoppers are choosing cheaper alternatives or local brands