rdata-visualizationstream-graph

streamgraphs dataviz in R won't plot


Has anyone checked out the great new dataviz package called streamgraphs?

Here are some examples: http://rpubs.com/hrbrmstr/streamgraph04

I'm looking to visualize revenue of five different products over time and want to see how it looks in a streamgraph. I melted my dataframe and it looks like the following:

   week variable    value
1    40     rev1  372.096
2    40     rev2  506.880
3    40     rev3 1411.200
4    40     rev4  198.528
5    40     rev5   60.800
6    43     rev1  342.912
7    43     rev2  501.120
8    43     rev3  132.352
9    43     rev4  267.712
10   43     rev5   82.368
11   44     rev1  357.504
12   44     rev2  466.560

So, the continuous variable is in the value column. I tried the following:

rev_plot %>%
  streamgraph("variable","value","week")

The error that I receive is the following:

Error in expand_(data, dots) : object '.' not found

I'm not quite sure what this means. I know the package is new, but I was wondering if anyone could help. Would really appreciate it!


Solution

  • A quick workaround (until I can squeeze time for coding up arbitrary continuous scales) is:

    # convert week number to a date
    
    rev_plot $week <- as.POSIXct(sprintf("2014 %d 1", rev_plot $week), 
                                 format = "%Y %U %u")
    
    # show intervals by week and format with only week number
    
    streamgraph(rev_plot, key="variable", date="week") %>%
      sg_axis_x(tick_interval=1, tick_units="week", tick_format="%U")
    

    enter image description here