Approaches for visualizing seasonality.
If our data have seasonal structure, it’s natural to compare individual periods against one another. In contrast to plotting the data in one long time series, seasonal plots reduce the amount of distance our eyes have to travel in order to compare two periods in a seasonal pattern. This also reduces the burden on our memory.
In R, we can use the gg_season
function to overlay all the seasons onto one another. The plot below shows antidiabetes drug sales over time. This view makes it clear that there is a spike in sales every January.
cols <- scales::viridis_pal()(10)
gg_season(as_tsibble(a10), pal = cols)
period
argument.gg_season(vic_elec, Demand, period = "day", pal = cols)
gg_season(vic_elec, Demand, period = "week", pal = cols)
period
argument like above.
{let line = vl.markLine({opacity: 0.8, size: 0.9})
.data(data)
.encode(
.x().fieldQ("time_in_week_").scale({domain: [0, 7]}),
vl.y().fieldQ("Demand"),
vl.detail().fieldN("week"),
vl.color().fieldN("year"),
vl.tooltip().fieldN("week")
vl
) .width(600);
return line.render()
}
robservable("@krisrs1128/seasonality", 4)