Interactive Data Visualization

DA 6233

Author

Justin Gould

Published

October 31, 2025

Variables in this Assignment

ROA (Return on Assets): oiadpq / atq - Measures how efficiently a company uses its assets Asset Turnover: saleq / atq - Measures how efficiently a company uses assets to generate sales Profit Margin: oiadpq / saleq - Operating income after depreciation as percentage of sales

ROA and Asset Growth

interactive scatter plot showing the relationship between Return on Assets (ROA) and Asset Growth for all companies, with animation by year.

chart <- data2.0 |> 
    filter(year >=  2015, year <= 2023, !is.na(saleq),!is.na("Asset Growth")) |> 
    ggplot(aes(
        x =log(saleq), y=`Asset Growth`, color = conm)) + 
    geom_point(aes(size = 3, alpha = 0.7, frame = year, ids = saleq)) +
    scale_y_continuous(
        breaks = c(-50, 0, 50), limits = c(-50, 75)) +
    labs(
        title = "Tech Company Performance: Sale vs Asset Growth",
        x = "Log(Sales)", 
        y = "Asset Growth (%)") +
    theme_minimal() + 
    theme(
        legend.position = "none",
        panel.grid.major.x = element_line(color = "gray90", linewidth = 0.3),
        panel.grid.major.y = element_line(color = "gray90", linewidth = 0.6),
        panel.grid.minor.y = element_line(color = "gray90", linewidth = 0.3)
    )

ggplotly(chart)

Annual Profit Margin

heatmap showing average annual profit margin by company and year

matrix <- data2.0 |> 
    filter(year >=  2015,
           year <= 2023) |> 
    group_by(conm, year) |> 
    summarise(avg_profit_margin = mean(`Profit Margin`, na.rm = TRUE), .groups = "drop") |>
    mutate(avg_profit_margin = round(avg_profit_margin * 100, 2),
           avg_profit_margin_label = percent(avg_profit_margin, accuracy = .01),
           year = as.factor(year),
           conm = as.factor(conm)) |> 
    select(avg_profit_margin, year, conm) |> 
    
    
    hchart("heatmap", 
           hcaes(x = year, y = conm, value = avg_profit_margin, name = conm, custom.year = year), 
    ) |>
    hc_add_theme(hc_theme_538()) |> 
    hc_colorAxis(stops = color_stops(colors = rev(c(
        "#0d47a1",
        "#1976d2",
        "#42a5f5", 
        "#ffb74d", 
        "#ff8a65",
        "#ff5722")))) |> 
    hc_xAxis(title = list(text = "Year")) |> 
    hc_yAxis(title = list(text = "")) |> 
    hc_title(text = '</span></strong></span> <span>&#128176;</span><span style="font-family: helvetica, inter, sans-serif;"><strong><span style="color: #black;"> Average Annual Profit Margin of Tech Giants',
             useHTML = TRUE) |> 
    hc_tooltip(
        xDateFormat = "%Y",
        headerFormat = "<b><span style='color:{series.color}; font-size:14px;'>{series.color}</span></b><br>",
        
        pointFormat = "<b>{point.name}</b> : {point.value:.2f}%",
        useHTML = TRUE)


matrix

Market capitalization

Market capitalization over time for the top 5 companies by current market cap, with custom tooltips.

# Find top 5 companies by latest market cap
q3 <- data2.0 |> 
    filter(year >= 2015, year <= 2024, conm %in% c(
        "ALPHABET INC", "AMAZON.COM INC", 
        "APPLE INC", "MICROSOFT CORP", 
        "NVIDIA CORP")) |>
    mutate(
        date = as.Date(datadate),
        mkt_cap = .000001 * (prccq * cshoq)) |> 
    hchart(
        "spline", 
        hcaes(x = date, y = mkt_cap, group = conm, value = conm),
        marker = list(enabled = TRUE)
    ) |> 
    hc_xAxis(
        type = "datetime",
        title = list(text = "Date")) |> 
    hc_yAxis(
        title = list(text = "Market Capitalization (Trillions $)")) |> 
    hc_add_theme(hc_theme_economist()) |> 
    hc_title(
        text = '<span>&#128200;</span> <strong style="color:black;">Market Cap Evolution of Tech Giants</strong>',
        useHTML = TRUE) |> 
    hc_tooltip(
        useHTML = TRUE,
        xDateFormat = "%A, %B %e, %Y",
        headerFormat = "<span style='font-size:12px;'>{point.key}</span><br>",
        pointFormat = "
      <span style='color:{series.color};font-weight:bold;'>
        {series.name}
      </span><br>
      Market Cap: <b>${point.y:.2f} T</b> 🏢")

q3

Profit Margin, Asset Turnover, and Revenue

The relationship between profit margin, asset turnover, and revenue (bubble size) for 2023 data.

q4 = data2.0 |> 
    filter(
        year == 2023,
        fqtr == 4, 
        `Profit Margin` >= -0.5, 
        `Profit Margin` <= 1,
        `Asset Turnover` >= 0,
        `Asset Turnover` <= 5) |> 
    mutate(`Profit Margin` = 100 * (`Profit Margin`)
    ) |> 
    hchart("bubble", hcaes(x = `Asset Turnover`, y = `Profit Margin`, group = conm, size = `Profit Margin`, name = conm, value = saleq)) |> 
    hc_add_theme(hc_theme_flat()) |> 
    hc_xAxis(
      title = list(text = "<span>💹</span> Asset Turnover (Revnue/Assets))")) |> 
    hc_yAxis(
    title = list(text = "<span>⚡</span> Profit Margin (Operating Income / Revenue)"),
    labels = list(format = "{value}%")) |>
    hc_add_theme(hc_theme_flat()) |> 
    hc_title(text = '</span></strong></span> <span>&#127919;</span><span style="font-family:Aptos Light;"><span style="color: #black;"> 2023 Q4: Efficiency vs Profitability (Bubble size = Revenue)',
             useHTML = TRUE) |> 
    hc_tooltip(
        headerFormat = "<span style='color:{series.color};font-weight:bold;'>
       {series.name}</span><br>",
        pointFormat = 
            "Asset Turnover: <b>{point.x:.2f} </b><br>
      Profit Margin: <b>{point.y:.1f}% </b><br>
      Revenue: <b>${point.value:.0f}M </b>",
        useHTML = TRUE
    )
q4

Year-over-Year Revenue Growth

Create a column chart showing year-over-year revenue growth for each company in 2023, with conditional coloring for positive/negative growth.

q5 <- data2.0 |>
  filter(year %in% c(2022, 2023)) |>
  group_by(conm, year) |> 
  summarise(
    annual_revenue = sum(saleq, na.rm = TRUE), .groups = "drop") |> 
  tidyr::pivot_wider(
    names_from = year, values_from = annual_revenue, names_prefix = "rev_") |> 
  mutate(
    revenue_growth = (rev_2023 - rev_2022) / rev_2022 * 100,        
    color = ifelse(revenue_growth >= 0, "#4CAF50", "#f44336"),
    label = paste0("<b>", round(revenue_growth,1), "%</b>")) |> 
  hchart(
    "column", hcaes(
      x = conm, 
      y = revenue_growth, 
      color = color, 
      dataLabels = label)) |> 
  hc_plotOptions(
    column = list(
      dataLabels = list(
        enabled = TRUE, 
        useHTML = TRUE, 
        format = "<b>{point.y:.1f}%</b>")))|> 
  hc_add_theme(hc_theme_google()) |> 
  hc_xAxis(
    title = list(text = "")) |> 
    hc_yAxis(
    title = list(text = "Revenue Growth (%)"),
    labels = list(format = "{value}%"),
    tickInterval = 20) |> 
  hc_title(
    text = '<span style="font-family:Poppins, Helvetica, sans-serif;">2023 Revenue Growth: Winners and Losers</span>',
    useHTML = TRUE) |> 
  hc_subtitle(text = 'NVIDIA is killing it') |> 
  hc_tooltip(
    headerFormat = "<span style='font-size:12px;'>{point.key}</span><br>",
    pointFormat = "Revenue Growth: <b>{point.y:.1f}%</b>")

q5