ramnathv / rCharts

Interactive JS Charts from R
http://rcharts.io
Other
1.19k stars 654 forks source link

Need equal size groups with Rickshaw() #176

Open jmwitten opened 11 years ago

jmwitten commented 11 years ago

Hi,

I'm having The following issue with Rickshaw:

I have data structured as Date, Group Name, Amount, Dates: 1-1000, 3 Total groups, and amount is an int.

However, one of the three groups does not get added as a group until halfway through the life of the data. so dates 1-100 lets say only have 2 entries per date, but dates 101+ have 3 entries per date. This prevents one from usings r5$layer with a group variable.

Is this by design, a problem with R, or a bug with the function?

Thanks!

ramnathv commented 11 years ago

Can you post your data (or a representative sample) somewhere and add a link here? It would be easier to debug with something concrete.

timelyportfolio commented 11 years ago

It is very hard to tell, but if using xts you can merge dates which will fill blanks with NA. These get passed to javascript as null. Here is an example using managers dataset which contains NA. See HAM6.

require(reshape2)
require(PerformanceAnalytics)
require(rCharts)

data(managers)

managers.melt <- melt(
  data.frame(
    index(managers),
    coredata(managers),
    stringsAsFactors = FALSE
  ), id.vars = 1
)

colnames(managers.melt) <- c("date","manager","return")

#get date in format that rickshaw likes
managers.melt$date <- as.double(
  as.POSIXct(
    as.Date(managers.melt$date),
    origin="1970-01-01"
  )
)

r1 <- Rickshaw$new()
r1$layer(
  y = "return",
  x = "date",
  group = "manager",
  min = "auto",
  data = managers.melt,
  type = "line"
)
r1