这不是一个错误,正如帮助中所说,它需要一个 JSON 字符串,因此您需要构建 JSON 字符串。
使用RJSONIO
您可以使用构建 JSON 选项toJSON
library(googleVis)
library(RJSONIO)
myColor <- 'grey' ## my dynamic color, here I fix but you can read it ,e.g
## from a chart config file or whatever you want
isLegend <- TRUE ## a boolean value
myseriesOptions <- toJSON(list(list(color=myColor),list(visibleInLegend=isLegend)))
例如
Scatter2 <- gvisScatterChart(women,
options=list(legend="none",
lineWidth=2, pointSize=0,
title="Women", vAxis="{title:'weight (lbs)'}",
hAxis="{title:'height (in)'}",
width=300, height=300,
series = myseriesOptions ))
plot(Scatter2)
PS:我们可以fromJSON
用来获取要构造的字符串的R形式,例如
fromJSON("{title:'mytitle'}") ## the ouptut is a list
$itl
NULL
cat(toJSON(list(title='mytitle'))) ## I construct my list and I use toJSON
## I get my origin json form
{
"title": "mytitle"
}