【发布时间】:2017-06-24 05:20:44
【问题描述】:
这是示例数据的代码:
library(tidyverse)
library(plotly)
df <- data_frame(
date = Sys.Date() - seq(0, 99, by = 0.2)[2:101],
cut = rep(c("Ideal", "Premium", "Very Good", "Good", "Fair"), 20),
y = sample_n(diamonds, size = 100)$depth,
z = sample_n(diamonds, size = 100)$price
)
这是情节的代码:
plot_ly(df, x = ~date, y = ~y, color = ~cut,
type = "scatter", mode = "lines") %>%
layout(
title = "Drop down menus - Change y",
xaxis = list(title = "x"),
yaxis = list(title = "y"),
updatemenus = list(
list(
y = 0.7,
buttons = list(
list(method = "restyle",
args = list("y", list(~y)),
label = "Show Y"),
list(method = "restyle",
args = list("y", list(~z)),
label = "Show Z")))
))
发生的事情是我执行了代码,绘制了绘图,并且它看起来像我想要的那样:随着时间的推移分类变量的事物计数。目标是让下拉菜单将一个 y 变量替换为另一个变量,在本例中为 z。
根据文档中的一些玩具示例和这里的一些答案,我觉得这应该可行。相反,看起来所有值都奇怪地折叠成一行。似乎没有办法在不重新运行代码的情况下将绘图恢复到原始状态。
有人知道如何让它正常工作吗?
这是我的plotly 版本:
packageVersion("plotly")
[1] ‘4.5.6.9000’
【问题讨论】: