R绘制的哑铃形动画图:下标超出范围

问题描述 投票:3回答:1

我正在尝试用plotlyR中制作动画哑铃图。

在示例here之后并使用信息here,我想到了以下代码:

df <- data.frame(
  category=c('a', 'b', 'c', 'd', 'a', 'b', 'c', 'd'),
  year=c(2000, 2000, 2000, 2000, 2001, 2001, 2001, 2001),
  val_a=c(1,2,2,1,2,5,6,8),
  val_b=c(3,5,4,7,1,9,2,12)
)

plot_ly(data = df, frame = ~year) %>%
  add_markers(x = ~val_a, y = ~category, name = "Val_A", color = I("red")) %>%
  add_markers(x = ~val_b, y = ~category, name = "Val_B", color = I("blue")) %>%
  add_segments(x = ~val_a, xend = ~val_b, y = ~category, yend = ~category, showlegend=F) %>%
  layout(
    title = "Val A v Val B",
    xaxis = list(title = "Value"), 
    yaxis = list(title = ""),
    margin = list(l = 65)
)  

不幸的是,这引发了以下错误:

Error in which(idx)[[1]] : subscript out of bounds
18.
registerFrames(p, frameMapping = frameMapping)
17.
plotly_build.plotly(instance)
16.
instance$preRenderHook(instance)
15.
createPayload(x)
14.
toJSON(createPayload(x))
13.
widget_data(x, id)
12.
htmltools::tagList(container(htmltools::tagList(x$prepend, widget_html(name = class(x)[1], package = attr(x, "package"), id = id, style = style, class = paste(class(x)[1], "html-widget"), width = sizeInfo$width, height = sizeInfo$height), x$append)), widget_data(x, id), if (!is.null(sizeInfo$runtime)) { ...
11.
toHTML(x, standalone = standalone)
10.
as.tags.htmlwidget(x, standalone = TRUE)
9.
htmltools::as.tags(x, standalone = TRUE)
8.
isTag(ui)
7.
rewriteTags(x, function(uiObj) { if (isTag(uiObj) || isTagList(uiObj) || is.character(uiObj)) return(uiObj) else return(tagify(as.tags(uiObj))) ...
6.
tagify(x)
5.
renderTags(html)
4.
save_html(html, file = index_html, background = background, libdir = "lib")
3.
html_print(htmltools::as.tags(x, standalone = TRUE), viewer = if (view) viewerFunc)
2.
print.htmlwidget(x)
1.
(function (x, ...) UseMethod("print"))(x)

但是,如果您使用标记段[[或来运行绘图代码,则可以正常工作。为什么然后我似乎不能将它们结合起来?

r plotly r-plotly
1个回答
0
投票
如果删除跟踪名称,您的代码将起作用! (名称=“ Val_A”)
© www.soinside.com 2019 - 2024. All rights reserved.