Load the libraries

library(httr)
library(jsonlite)
library(ggplot2)

Extract the API and transform into usable data for R

url <- "https://api.spacexdata.com/v4/launches"
resp <- GET(url)
data <- fromJSON(content(resp, "text"), flatten = TRUE)

Extract launch names + dates

launch_data <- data.frame(
  name = data$name,
  date = as.Date(data$date_utc)
)

Count launches per year

launch_data$year <- format(launch_data$date, "%Y")
launch_counts <- as.data.frame(table(launch_data$year))
colnames(launch_counts) <- c("year", "count")

Convert ‘year’ to numeric for plotting

launch_counts$year <- as.numeric(as.character(launch_counts$year))
launch_counts$count <- as.numeric(launch_counts$count)  # just in case

Plot launches per year

ggplot(launch_counts, aes(x = year, y = count, group = 1)) +
  geom_line(color = "steelblue", linewidth = 1.2) +
  geom_point(color = "darkred", size = 3) +
  theme_minimal() +
  labs(
    title = "SpaceX Launches per Year",
    x = "Year",
    y = "Number of Launches"
  )