Change streamgraph shape



By definition a streamgraph has rounded angles, giving a nice feeling of flow. It is possible to change this shape using an option of the streamgraph package.

Streamgraph section Data to Viz

By definition a streamgraph displays rounded shapes like on the left chart above. It gives a nice impression of flow and is well known for it.

The streamgraph package also allows to interpolate data points differently. Use linear to get something close to a stacked area graph. Use step to mimick a stacked barplot.

Note: you can save the chart as a html file using the saveWidget() function of the htmlwidgets package, as suggested in the commented code below.

# Library
library(streamgraph)

# Create data:
data <- data.frame(
  year=rep(seq(1990,2016) , each=10),
  name=rep(letters[1:10] , 27),
  value=sample( seq(0,1,0.0001) , 270)
)

# Shape: classic
p1 <- streamgraph(data, key="name", value="value", date="year",
    width="400px", height="300px"
    )

# Shape: stacked area graph
p2 <- streamgraph(data, key="name", value="value", date="year" ,interpolate="linear" ,
    width="400px", height="300px"
    )

# Shape: stacked barplot
p3 <- streamgraph(data, key="name", value="value", date="year" ,interpolate="step" ,
    width="400px", height="300px"
    )

# save the widget
# library(htmlwidgets)
# saveWidget(p1, file=paste0( getwd(), "/HtmlWidget/streamgraphShape1.html"))
# saveWidget(p2, file=paste0( getwd(), "/HtmlWidget/streamgraphShape2.html"))
# saveWidget(p3, file=paste0( getwd(), "/HtmlWidget/streamgraphShape3.html"))

Related chart types


Line plot
Area
Stacked area
Streamchart
Time Series



❤️ 10 best R tricks ❤️

👋 After crafting hundreds of R charts over 12 years, I've distilled my top 10 tips and tricks. Receive them via email! One insight per day for the next 10 days! 🔥