Skip to contents

The areaY mark creates filled area charts. It’s perfect for showing cumulative data, trends over time, or emphasizing the magnitude of values.

Basic Example

# Sample data
data <- data.frame(
  category = c("A", "B", "C", "D", "E", "F", "G", "H"),
  value = c(2, 8, 3, 7, 5, 4, 6, 1)
)

spec <- list(
  plot = list(
    list(
      mark = "areaY",
      data = list(from = "sample_data"),
      x = "category",
      y = "value",
      fill = "steelblue"
    )
  )
)

mosaic(spec, sample_data = data)

Customization Options

Time Series Area

# Time series data
time_data <- data.frame(
  date = seq(as.Date("2023-01-01"), as.Date("2023-12-31"), by = "month"),
  revenue = c(100, 120, 115, 130, 145, 160, 155, 170, 165, 180, 190, 200)
)

spec_time <- list(
  plot = list(
    list(
      mark = "areaY",
      data = list(from = "time_data"),
      x = "date",
      y = "revenue",
      fill = "lightgreen",
      fillOpacity = 0.7
    )
  )
)

mosaic(spec_time, time_data = time_data)

Stacked Areas

# Stacked area data
stacked_data <- data.frame(
  month = rep(1:6, times = 3),
  category = rep(c("Product A", "Product B", "Product C"), each = 6),
  sales = c(
    c(20, 25, 30, 28, 35, 40),  # Product A
    c(15, 18, 22, 25, 28, 30),  # Product B
    c(10, 12, 15, 18, 20, 25)   # Product C
  )
)

spec_stacked <- list(
  plot = list(
    list(
      mark = "areaY",
      data = list(from = "stacked_data"),
      x = "month",
      y = "sales",
      fill = list(column = "category"),
      fillOpacity = 0.8
    )
  )
)

mosaic(spec_stacked, stacked_data = stacked_data)

Area with Outline

spec_outlined <- list(
  plot = list(
    list(
      mark = "areaY",
      data = list(from = "time_data"),
      x = "date",
      y = "revenue",
      fill = "lightcoral",
      fillOpacity = 0.6,
      stroke = "darkred",
      strokeWidth = 2
    )
  )
)

mosaic(spec_outlined, time_data = time_data)

Use Cases

  • Time Series: Excellent for showing trends and changes over time
  • Cumulative Data: Perfect for displaying running totals or cumulative values
  • Part-to-Whole: Stacked areas show how parts contribute to the whole
  • Magnitude Emphasis: The filled area emphasizes the size of values
  • Financial Data: Common in financial charts for showing revenue, profit, etc.