【发布时间】:2019-11-08 16:23:44
【问题描述】:
我有一个包含不同列的数据框。第一个是年份,其余的是不同的品牌。我想绘制一张图表,显示这些不同品牌多年来在利润方面的表现。这个图表应该有一个下拉菜单,允许您选择您想查看的公司,这是一个包含所有品牌的下拉复选框。该复选框还应该允许您同时查看所有这些,或者只查看一些。
#Here is my go at it.
library(plotly)
x <- seq(-2 * pi, 2 * pi, length.out = 1000)
df <- data.frame(x, y1 = sin(x), y2 = cos(x), y3=cos(2*x), y4=sin(3*x))
p <- plot_ly(df, x = ~x) %>%
add_lines(y = ~y1, name = "Sin") %>%
add_lines(y = ~y2, name = "Cos", visible = F) %>%
layout(
title = "Drop down menus - Styling",
xaxis = list(domain = c(0.1, 1)),
yaxis = list(title = "y"),
updatemenus = list(
list(
y = 0.7,
buttons = list(
list(method = "restyle",
args = list("visible", list(TRUE, FALSE)),
label = "Sinx"),
list(method = "restyle",
args = list("visible", list(FALSE, TRUE)),
label = "Cosx")))
)
)
p
在上面的示例中,我能够创建一个下拉菜单,但它并不接近我想要的。另外,我无法理解question 中给出的答案,因为它使用了太多的 html(我很讨厌 html)。非常感谢任何帮助。
【问题讨论】: