The areaY
mark creates filled area charts. It’s perfect
for showing cumulative data, trends over time, or emphasizing the
magnitude of values.
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)
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.