这里的上下文是用于统计计算的R项目

考虑以下代码(来自chartJSRadar文档)

library(radar chart)
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)


我想在使用中画上一个传说:

legend("topleft", c("Rich","Andy","Aimee"), cex=0.8, fill=colors)


但我收到以下错误:

Error in strwidth(legend, units = "user", cex = cex, font = text.font) :
  plot.new has not been called yet


我还看到了有关此错误消息的许多其他问题。其中一些是因为图例坐标不在图表中。其他一些人提供了一种解决方法,但没有解释错误发生的原因。

我的问题是:为什么我会收到此错误?似乎从根本上来说是错误的,例如legend()和chartJSRadar()之间的不兼容,但我不明白。

请指教!

最佳答案

似乎chartJSRadar不会调用图,而是在查看器中显示交互式图。因此,不会调用绘图,并且不能使用legend()。从chartJSRadar的文档看来,雷达图似乎有图例选项,请参见http://www.chartjs.org/docs/#radar-chart-chart-options

//String - A legend template
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"


这是JavaScript,我没有专门知识,所以很遗憾,这是我能为您提供的帮助。

关于r - 为什么在chartJSRadar()之后调用legend()导致“plot.new尚未被调用”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36449864/

10-11 05:48