ululalbab / google-motion-charts-with-r

Automatically exported from code.google.com/p/google-motion-charts-with-r
0 stars 0 forks source link

Undefined "combinations of idvar and timevar" error #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Loading data from console: time <- c("12.15.2011 7:41:52", "12.15.2011 
7:43:07", "12.15.2011 17:53:08", "12.15.2011 17:58:19", "12.15.2011 17:59:13", 
"12.15.2011 18:09:33", "12.15.2011 18:14:02", "12.15.2011 18:16:11", 
"12.15.2011 18:24:07", "12.15.2011 18:32:27", "12.15.2011 20:00:33", 
"12.15.2011 20:49:44", "12.15.2011 22:04:33", "12.15.2011 23:03:45", 
"12.15.2011 23:25:37", "12.16.2011 2:48:53", "12.16.2011 5:47:36", "12.16.2011 
9:47:38", "12.16.2011 19:34:55", "12.16.2011 19:52:47", "12.16.2011 19:53:19", 
"12.16.2011 19:53:37", "12.16.2011 20:13:50", "12.16.2011 21:06:16", 
"12.16.2011 21:35:09", "12.16.2011 21:46:28", "12.16.2011 22:30:20", 
"12.16.2011 23:57:28", "12.17.2011 11:31:57", "12.17.2011 11:44:14", 
"12.17.2011 14:37:00", "12.18.2011 13:10:15", "12.19.2011 11:09:43", 
"12.19.2011 13:59:43", "12.19.2011 14:20:26", "12.19.2011 14:47:19", 
"12.19.2011 19:37:59", "12.20.2011 12:41:37", "12.20.2011 13:04:03", 
"12.20.2011 13:46:25")
choice <- c("Option 1", "Option 2", "Option 1", "Option 2", "Option 2", "Option 
1", "Option 2", "Option 1", "Option 1", "Option 2", "Option 2", "Option 1", 
"Option 2", "Option 2", "Option 2", "Option 1", "Option 2", "Option 1", "Option 
2", "Option 2", "Option 1", "Option 2", "Option 2", "Option 2", "Option 2", 
"Option 2", "Option 2", "Option 2", "Option 2", "Option 1", "Option 1", "Option 
2", "Option 1", "Option 2", "Option 2", "Option 2", "Option 2", "Option 2", 
"Option 2", "Option 2")
data <- data.frame(time, choice)

2. Transforming dateTime stamp to date format:
data$time <- strptime(data$time, "%m.%d.%Y %H:%M:%S")
data$time <- as.Date(data$time, format="%Y-%m-%d %H:%M:%S")

3. Starting googleVis library and trying to use gvisMotionChart function:
library(googleVis)
M <- gvisMotionChart(data, idvar = "choice", timevar="time")

I get an error:
Error in gvisCheckMotionChartData(data, my.options) : 
  The data must have rows with unique combinations of idvar and timevar.
Your data has 40 rows, but idvar and timevar only define 10 unique rows.

If I call fix(data), I see that everything is fine with my data. All 40 cases 
are defined properly.

I have R 2.13.2,  googleVis version 0.2.12, Windows 7 OS.

Please provide any additional information below.

Original issue reported on code.google.com by dr.zan...@gmail.com on 21 Dec 2011 at 8:39

GoogleCodeExporter commented 9 years ago
## I can confirm that I get the same message:

M <- gvisMotionChart(data, idvar = "choice", timevar="time")
## Error in gvisCheckMotionChartData(data, my.options) : 
##   The data must have rows with unique combinations of idvar and timevar.
##  Your data has 40 rows, but idvar and timevar only define 10 unique rows.

head(data)

##         time   choice
## 1 2011-12-15 Option 1
## 2 2011-12-15 Option 2
## 3 2011-12-15 Option 1
## 4 2011-12-15 Option 2
## 5 2011-12-15 Option 2
## 6 2011-12-15 Option 1

## 
## Your data set has, as the error message suggest several values for the same 
date.
## For 2011-12-15 Option 1 appears several times.
## A motion chart requires unique rows for each 'idvar' / 'timevar' 
combination. 
## Further, a value to plot is missing.
## I suggest that you aggregate your data to a day level first.
##
## Here is an extended example which works for me:

df=unique(data)
df$value=rnorm(nrow(df))
M <- gvisMotionChart(df, idvar = "choice", timevar="time")
plot(M)

## Your observation is as expected.
## Please let me know if we can improve the documentation.

Original comment by markus.g...@googlemail.com on 21 Dec 2011 at 9:05

GoogleCodeExporter commented 9 years ago
Yes, I've already solved the problem. I had to make my data matrix as follows:
time choice quantity
date1 Option 1 Sum_of_Option 1_occurancies_on_date1
date1 Option 2 Sum_of_Option 2_occurancies_on_date1
date2 Option 1 Sum_of_Option 1_occurancies_on_date2
date2 Option 2 Sum_of_Option 2_occurancies_on_date2
...
Now have the graph:
http://masscom.ucoz.ua/test.html

Original comment by dr.zan...@gmail.com on 21 Dec 2011 at 9:14

GoogleCodeExporter commented 9 years ago
I am glad to hear that you could solve your issue.

Original comment by markus.g...@googlemail.com on 21 Dec 2011 at 10:08