我想创建一个带有updatemenu()
作为日期的时间序列条形图。我已经创建了菜单,但是我不知道如何将其与我的条形图连接。
date<-c("2007-12-31","2008-01-01","2008-01-02")
t1<-c(2200,3455,3456)
t2<-c(2280,3457,3456)
kl<-data.frame(date,t1,t2)
p <- plot_ly(kl,x = kl$D, y = kl$y, type = 'bar', name = 'Real Estate Index 1', marker = list(color = 'rgb(49,130,189)'),
xbins = list(
end = "2008-01-02",
size = "M1",
start = "2007-12-31"
)) %>%
add_trace(kl,y = kl$z, name = 'Real Estate Index 2', marker = list(color = 'rgb(204,204,204)')) %>%
layout(xaxis = list(title = "", tickangle = -45),
yaxis = list(title = ""),
margin = list(b = 100),
barmode = 'group',
updatemenus = list(
list(
x = 0.1,
y = 1.15,
active = 1,
showactive = TRUE,
buttons = list(
labels("D1", "Day"),
labels("M1", "Month"),
labels("M6", "Half Year"),
labels("M12", "Year")
)
)
))
p