hrbrmstr / streamgraph

:wavy_dash: htmlwidget for creating streamgraph visualizations in R
http://hrbrmstr.github.io/streamgraph/
Other
148 stars 49 forks source link

FR: Use numeric, non-date variables as x-var #4

Closed jemus42 closed 9 years ago

jemus42 commented 9 years ago

I was wondering if I could use non-date variables on the x axis for data that is inherently sequential, but not necessarily timestamped.

Take for example trakt.tv episode data (sorry for plugging my own package):

devtools::install_github("jemus42/tRakt")
library(tRakt); library(dplyr) 
get_trakt_credentials(client.id = "12fc1de7671c7f2fb4a8ac08ba7c9f45b447f4d5bad5e11e3490823d629afdf2")

got <- trakt.getEpisodeData(target = "game-of-thrones", season_nums = c(1, 2, 3, 4))

got %>% select(epnum, rating, votes, season, episode) %>% head
  epnum  rating votes season episode
1     1 8.71855  2750      1       1
2     2 8.69493  2111      1       2
3     3 8.60256  1955      1       3
4     4 8.67887  1884      1       4 
5     5 8.71903  1808      1       5
6     6 8.95666  1846      1       6

I was hoping to generate a stream of episodes, but since a variable that can be coerced to a date is expected, this

got %>%
  streamgraph("episode", "votes", "epnum", offset = "zero", interpolate = "step") 

fails with

Error in as.Date.numeric(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, : 'origin' must be supplied

I did try to use the episode airdates instead of the absolute episode number, but the result seems… weird. Example:

got %>% streamgraph("episode", "votes", "firstaired.posix", interpolate = "step")

Produces unevenly sized bars because of the irregularities in the airdates

unevenly sized bars

I'm not sure if what I'm asking is even possible or meant to be possible within this package, but since I'm very happy about the possibilities this package presents, I thought this might be a low hanging fruit.

hrbrmstr commented 9 years ago

aye. it's totally possible. and it's now officially on the TODO list! ETA is some time in early March. thx.

jemus42 commented 9 years ago

Thanks a lot!

As someone with no JavaScript skills at all, I greatly appreciate htmlwidgets like this <3

hrbrmstr commented 9 years ago

Latest release (0.6) should support continuous variable for the x axis. Will support categorical soon.