0

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!

itjcms18
  • 3,993
  • 7
  • 26
  • 45
  • The examples given on the author's github page fail with the same error. I suspect there's a problem with the package. https://github.com/hrbrmstr/streamgraph – cory Feb 25 '15 at 19:12
  • The package clearly states it needs dates. It doesn't work with arbitrary continuous values. There's a feature request for this enhancement in the issues. – hrbrmstr Feb 25 '15 at 19:13
  • 1
    Latest rev (0.6) on github repo now supports continuous x axis scale (as an alternative to date scales) – hrbrmstr Mar 07 '15 at 17:53

2 Answers2

2

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

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
0

You can simply add the parameter scale = "continuous" in your streamgraph argument, without changing your data frame.

I have tried the following and it works.

rev_plot %>%
  streamgraph("variable","value","week", scale = "continuous")
y26805
  • 1