Change streamgraph color



The streamgraph package offers several options to control the color palette in use. Both R Color Brewer and custom color palette are supported.

Streamgraph section Data to Viz

The streamgraph package offers a few options to customize the chart color:

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

# Graph 1: choose a RColorBrewer palette -> continuous
p1 <- streamgraph(data, key="name", value="value", date="year",
    width="400px", height="300px"
    ) %>%
  sg_fill_brewer("Blues")

# Graph 2: choose a RColorBrewer palette -> categorical
p2 <- streamgraph(data, key="name", value="value", date="year",
    width="400px", height="300px"
    ) %>%
  sg_fill_brewer("Pastel1")

# Graph 3: choose color manually with number, color name, rgb ...
p3 <- streamgraph(data, key="name", value="value", date="year"  ,
    width="400px", height="300px"
    ) %>%
  sg_fill_manual(c(1:10))

# save the widget
# library(htmlwidgets)
# saveWidget(p1, file=paste0( getwd(), "/HtmlWidget/streamgraphColor1.html"))
# saveWidget(p2, file=paste0( getwd(), "/HtmlWidget/streamgraphColor2.html"))
# saveWidget(p3, file=paste0( getwd(), "/HtmlWidget/streamgraphColor3.html"))

Related chart types


Line plot
Area
Stacked area
Streamchart



Contact

This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message on Twitter, or send an email pasting yan.holtz.data with gmail.com.

Github Twitter