From e598715ba5aad2345f03650452e2c1928569d28d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=92=A7=E5=A4=A9?= Date: Thu, 5 May 2022 20:22:53 -0400 Subject: [PATCH] new interactive --- 06-interactive.Rmd | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/06-interactive.Rmd b/06-interactive.Rmd index b025870..4187070 100644 --- a/06-interactive.Rmd +++ b/06-interactive.Rmd @@ -4,16 +4,18 @@ library(plotly) ``` -## Add Buttons +## Add Buttons and Range Slider We put the volatility of USDC and USDT into one plot because the volatility of the two cryptos have similar trends. In this interactive plot, we create three buttons that includes three options: showing the volatility of USDC, showing the volatility of USDT, and showing both cryptos. +In this interactive plot, we also add the range slider, so if people want to observe the plot of volatility in a specific range, the can move the buttons which are in the two side of the range slider. + ```{r} ##set the dataframe df_USDC<-df.crypto[df.crypto$cryptocurrency =="USDC",] df_USDT<-df.crypto[df.crypto$cryptocurrency =="USDT",] -df_J_I<-data.frame(cbind(df_USDT$Date,df_USDT$volatility, - df_USDC$volatility)) +df_J_I<-data.frame(cbind(format(as.Date(df_USDC$Date),"%Y/%m/%d"), + df_USDT$volatility,df_USDC$volatility)) colnames(df_J_I) <- c("Date","USDT_vol","USDC_vol") fig_J_I <- plot_ly(df_J_I, type = "scatter" , mode = "lines") fig_J_I<- fig_J_I %>% add_lines(x=~Date, y=~USDT_vol, name="USDT", @@ -46,17 +48,8 @@ fig_J_I_update <- fig_J_I %>% layout(title = "Volatility", showlegend=FALSE, yaxis=list(title="Volatility"), updatemenus=update_trace) -fig_J_I_update -``` - -## Range Slider - -In this interactive plot, we add the range slider, so if people want to observe the plot of volatility in a specific range, the can move the buttons which are in the two side of the range slider. - -```{r} -fig_J_I_range<-fig_J_I%>% +fig_J_I_update%>% layout(xaxis = list(rangeslider = list(visible = T))) -fig_J_I_range ```