Introduction
This article describes how to go from a crosstab containing at least one numeric or date variable for the rows:
To a state where you have a type of stacked area chart called a streamgraph where it is modified so that the streams are centered around the y-axis:
Requirements
You will need to have one of the following:
- A crosstab that has a numeric or date variable set as the rows.
- Variables, including at least one numeric or date variable, that are suitable for crosstabbing, or
- Crosstab with input data that is stored in a spreadsheet document with a numeric or date variable set as the rows.
Method
From the toolbar, select Create > Charts > Visualization > Time Series > Stream. We can input data to the streamgraph in three different ways.
Option 1: Output – select a table output. Note that for a streamgraph, the row names of the output must be dates or numeric.
Option 2: Variables – select two or more variables from an imported Data Set. The first variable, which will be used for the x axis, should be a date or numeric variable. The remaining variables will be used as y coordinates of different series on the streamgraph.
Option 3: Paste or type data – directly enter data into a spreadsheet object into Displayr. This input should be in a similar form to the first option, with date or numeric row names in the furthest left column.
Customizing the streamgraph
In most cases, the default settings will give a sensible chart. However, if you want to change the colors used in the streamgraph or to adjust the x or y axis ticks, additional controls can be found in the Chart tab of the Object Inspector.
In the streamgraph below, we have changed both the tick format for both the x and y axis. Note that you need to change the axis number type before you can specify formats. Depending on the number type, different format types will be offered. You can also set the format type to custom which will allow you to set any D3 format.
Because the streamgraph is so specialized, it is not as flexible as many of the other chart types. In particular, the margins do not adjust automatically. In the second example, changing the y axis type to scientific notion also increased the width of the tick labels. To account for this, we needed to increase the left margin from 30 to 45.
Related Charts
The streamgraph can be visually appealing, but it also suffers from a number of legibility issues. Specifically, its centering around the y-axis makes it difficult to judge the height of distinct series. You may instead want to try using an Area Chart. For instance, compare the streamgraphs above with the (stacked) area chart below.
NEXT
How to Create a Time Series Graph
How to Set Time Periods for Date Questions
How to Smooth a Time Series in Q
How to Do Time Series Analysis in Q