gVisMotionChart 给出了唯一行的问题

gVisMotionChart gives issue with unique rows

我正在尝试使用 gVisMotion 图表,但出现错误。

gg=gvisMotionChart(data, idvar='NY.GNP.PCAP.CD',   timevar='year',options=list())
 Error in gvisCheckMotionChartData(data, my.options) : 
 The data must have rows with unique combinations of idvar and timevar.
 Your data has 9982 rows, but idvar and timevar only define 6328 unique rows.

这就是我正在做的

 dat = WDI(indicator='NY.GNP.PCAP.CD', country="all",start=1970, end=2016)
 l = dim(dat)
 #Subset countries
 data <- dat[2163:l[1],]
  gg=gvisMotionChart(data, idvar='NY.GNP.PCAP.CD', timevar='year',options=list())

我得到了错误

Error in gvisCheckMotionChartData(data, my.options) : The data must have rows with unique combinations of idvar and timevar. Your data has 9982 rows, but idvar and timevar only define 6328 unique rows.

 head(data)
 iso2c     country      NY.GNP.PCAP.CD year
2163    AF Afghanistan            630 2015
2164    AF Afghanistan            670 2014
2165    AF Afghanistan            730 2013
...

很可能 NY.GNP.PCAP.CD & year 有一些针对不同国家/地区的重复行。不是吗?

我做错了什么?如何解决?

idvar='NY.GNP.PCAP.CD'应该改为idvar='country'。直觉是不同的国家(甚至同一个国家)在不同的年份可能有相同的国民生产总值——这就是为什么你会得到那个错误。 运行 此代码有效。

data <- dat[2163:l[1],]
  gg=gvisMotionChart(data, idvar='idvar='country'', timevar='year',options=list())