Control streamgraph offset



The streamgraph package offers several options concerning the chart offset. This feature has a massive impact on the general appearance. This post provides a description of the options.

Streamgraph section Data to Viz

This post follows the previous basic streamgraph. It shows the effect of the offset option that can take 3 values:

Note: The streamgraph package is a work by Bob Rudis. It lives on github.

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)
)

# Type 1 (default)
p1 <- streamgraph(data, key="name", value="value", date="year" , 
    offset="silhouette",
    width="400px", height="300px"
    )
 
# Type 2 
p2 <- streamgraph(data, key="name", value="value", date="year" , 
    offset="zero",
    width="400px", height="300px"
    )
 
# Type 3.
p3 <- streamgraph(data, key="name", value="value", date="year" , 
    offset="expand",
    width="400px", height="300px"
    )

# save the widget
# library(htmlwidgets)
# saveWidget(p1, file=paste0( getwd(), "/HtmlWidget/streamgraphOffset1.html"))
# saveWidget(p2, file=paste0( getwd(), "/HtmlWidget/streamgraphOffset2.html"))
# saveWidget(p3, file=paste0( getwd(), "/HtmlWidget/streamgraphOffset3.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! 🔥