将自定义选项传递给 radarChartJS 时出错

Error passing custom options to radarChartJS

我正在尝试根据 http://www.chartjs.org/docs/#chart-configuration-creating-a-chart-with-options 将自定义选项传递给 chartJSRadar。在此示例中,我尝试传递一个简单的标题,但遇到此错误:

Error in validateCssUnit(sizeInfo$width) : CSS units must be a single-element numeric or character vector

示例代码:

library(radarchart)

labs <- c("Communicator", "Data Wangler", "Programmer",
          "Technologist",  "Modeller", "Visualizer")

scores <- list(
  "Rich" = c(9, 7, 4, 5, 3, 7),
  "Andy" = c(7, 6, 6, 2, 6, 9),
  "Aimee" = c(6, 5, 8, 4, 7, 6)
)


opList <- list(title=list(display='true', text='Title'))
chartJSRadar(scores = scores, labs = labs, maxScale = 10, opList)

我相信你只需要稍微改变一下你的 opList 论点。 chartJSRadar 使用 ... 作为传递附加选项的地方。在您的代码中, opList 被假定为 width 参数。通常,我会说大多数 htmlwidgetsheightwidth 放在最后,这样就不会发生这种情况,但是 chartJSRadar 不遵循此约定。

这应该有效,但没有,因此探索错误的来源。它所基于的 chartJS 的旧版本似乎不提供 title。我添加了代码来展示如何手动添加 title.

library(radarchart)

labs <- c("Communicator", "Data Wangler", "Programmer",
          "Technologist",  "Modeller", "Visualizer")

scores <- list(
  "Rich" = c(9, 7, 4, 5, 3, 7),
  "Andy" = c(7, 6, 6, 2, 6, 9),
  "Aimee" = c(6, 5, 8, 4, 7, 6)
)


chartJSRadar(
  scores = scores, labs = labs, maxScale = 10,
  title = list(display = TRUE, text = "Custom Title")
)

我快速整合了一个更新,您可以尝试使用,但它尚未经过测试,还没有准备好发布。

devtools::install_github("timelyportfolio/radarchart@update/2.1.6")