在googleVis图表中更改图例标签

时间:2015-07-14 12:05:57

标签: r googlevis

如何更改googleVis图表中的默认图例标签?

我尝试了什么

我看到有labelInLegend设置,我可以对选项进行硬编码,如下所示:

  library(data.table)
  library(googleVis)

  test.dt  <- data.table(day = c(1,2,3), value = c(0.8,1.2,1.2), 
                         price = c(1,1.1,1.2), name = c("A","A","A"))


  # set chart options in hamfisted hardcoded way
  testop <- list(series = "[{labelInLegend: 'A price'},
                            {labelInLegend: 'A value'}]",
                 legend = chart.op$op.legend)

  testplotdatay <-  c("price", "value")

  plot(gvisLineChart(test.dt, 
                     xvar = "day",
                     yvar = testplotdatay,
                     options = testop))

得到:  GoogleLinechartLegend

但是,如何以参数化方式开展此工作?

您是否仍需要将JSON字符串发送到googleVis as this old answer suggests,还是现在有更简单的方法?例如,googleVis现在支持数据角色(对于AnnotationText,范围)。

任务

我希望在绘制的数字字段前添加名称,以区分何时选择多个公司,例如图例中的价格,B价格。

mylabels <- paste(unique(test.dt$name), testplotdatay) 
# i.e. "A price" "A value" 

我试图发送给googleVis但没有运气:

testop <- list(labelInLegend  = mylabels)

testop <- list(series.labelInLegend  = mylabels)

经验丰富的googleVis用户会做些什么?

并且,如果我必须使用toJSON()来参数化正确的语法?

编辑:googleVis 0.5.9,R 3.1.3

0 个答案:

没有答案
相关问题