Streamgraph is a type of stacked area graph which is displaced around a central axis, resulting in a flowing, organic shape. Streamgraphs and their use were popularized by Lee Byron in a February 2008 New York Times article on movie box office revenues.

Data

Here we have census data about GDP values in some counties in southeast China.

Census GDP data


Convert to 1-dimensional table

We have a 2-dimensional table above. Before drawing streamgraph, we need to convert 2-dimensional table to 1-dimensional table. We can use Microsoft Excel to convert it.

Press Alt + D + P, then we have the widget.

Step1

Step2

Select the data need to be ploted.
Step3

Hit complate.
Step1

Now we have a new table, double click the bottom right sum value. Then we will have a 1-dimensional table.

1-dimensional table


Draw the graph in Rstudio

Because read_csv can not read Chinese characters correctly, we use read_excel to input the data.

1
2
library(readxl)
df = read_excel("your_file_path/one_dimension.xlsx")

Install streamgraph package from github.

1
devtools::install_github("hrbrmstr/streamgraph")

Draw the graph;

1
2
3
4
streamgraph(df, key="name", value="gdp", date="year" , offset="zero") %>%
sg_fill_tableau() %>% # set color
sg_axis_x(tick_interval = 1) %>% # set x-axis interval as one year
sg_legend(TRUE, "Name: ") # add legend

Streamgraph of Jiangsu GDP

Streamgraph of Jiangsu GDP: user select one county


References

GitHub | hrbrmstr | streamgraph

Art from data | #155 INTERACTIVE STREAMGRAPH | CHANGE OFFSET