R Steamgraph error: "invalid subscript type list"

2.2k views Asked by At

I get the following error using the steamgraph package

 library(streamgraph)
 streamgraph(data, "Keys" ,"Box.Office", date = 11-11-2011, interactive=TRUE)
Error in .subset(x, j) : invalid subscript type 'list'

Sample of the data:

days;Box.Office;Key

1; 2324234;Lucy

2; 123123;Lucy

3; 898989;Lucy

.....

1; 231231;Interstellar

2; 32423;Interstellar
1

There are 1 answers

4
SabDeM On

First thing first, there is a typo in your code: Keys should be Key and the interactive argument is set to TRUE by default, you do not need to specify it.

Most likely the problem is that streamgraph does not know how to deal with the days column, in fact if you change the days column with something (numeric or character) that can be converted to as.Date it works well.

The example of the official page show that all example do have column (numeric or character) that can be interpreted as valid date, furthermore you can explore the body of the function with just typing streamgraph in R and you'll see more closely what it does.

With the provided data, to allow function work you need other informations. Here is an example where I have converted the days column to dates. It works well and produce the plot.

library(streamgraph)
streamgraph(df, "Key" ,"Box.Office", "days")

just use this data:

df <- structure(list(days = structure(c(0, 1, 2, 0, 1), class = "Date"), 
    Box.Office = c(2324234L, 123123L, 898989L, 231231L, 32423L
    ), Key = c("Lucy", "Lucy", "Lucy", "Interstellar", "Interstellar"
    )), .Names = c("days", "Box.Office", "Key"), row.names = c(NA, 
-5L), class = "data.frame")