R/plotly:拖动滑块而不是自动播放 [英] R/plotly: Dragging Sliders Instead of Autoplay
问题描述
我正在使用R编程语言.使用之前关于stackoverflow的问题(
但是,似乎不可能拖曳"到目标.圆形滑动按钮"(由红色箭头指示).看来我只能按播放按钮"和动画自动播放.有没有一种方法可以修改此代码,以便您可以拖动"代码.圆形的滑块按钮跨过?
谢谢
我的会话信息
>sessionInfo()R版本4.0.3(2020-10-10)平台:x86_64-w64-mingw32/x64(64位)运行于:Windows 10 x64(内部版本19041)矩阵产品:默认语言环境:[1] LC_COLLATE =英语_加拿大.1252 LC_CTYPE =英语_加拿大.1252 LC_MONETARY =英语_加拿大.1252[4] LC_NUMERIC = C LC_TIME = English_Canada.1252附带的基本软件包:[1]统计图形grDevices utils数据集方法库其他附件包:[1] plotly_4.9.3 ggplot2_3.3.3 dplyr_1.0.3通过名称空间(未附加)加载:[1]支柱_1.4.7编译器_4.0.3工具_4.0.3摘要_0.6.27 jsonlite_1.7.2生命周期_0.2.0[7] tibble_3.0.5 gtable_0.3.0 viridisLite_0.3.0 pkgconfig_2.0.3 rlang_0.4.10 cli_2.2.0[13] rstudioapi_0.13 withr_2.4.1 httr_1.4.2generics_0.1.0 vctrs_0.3.6 htmlwidgets_1.5.3[19] grid_4.0.3 tidyselect_1.1.0胶水_1.4.2 data.table_1.13.6 R6_2.5.0 fansi_0.4.2[25] purrr_0.3.4 tidyr_1.1.2 magrittr_2.0.1 scales_1.1.1省略号_0.3.1 htmltools_0.5.1.1[31]断言_0.2.1 colorspace_2.0-0 utf8_1.1.4 lazyeval_0.2.2 munsell_0.5.0 crayon_1.3.4
您根本不需要更改任何内容!只需单击并拖动.您的 exact 代码对我而言效果很好.而且这也不是一项新功能,因为我在RStudio中使用 Package plotly版本4.9.1
.
点击
拖动
I am working with the R programming language. Using this previously asked question on stackoverflow ( Slider for Plotly R), I was able to make a "slider animation" (using the "plotly" library) for different values of (a variable called) "var" within the data set:
#load libraries
library(plotly)
library(dplyr)
library(ggplot2)
#generate data
var = rnorm(731, 100,25)
date= seq(as.Date("2014/1/1"), as.Date("2016/1/1"),by="day")
data = data.frame(var,date)
#aggregate data
aggregate = data %>%
mutate(date = as.Date(date)) %>%
group_by(month = format(date, "%Y-%m")) %>%
summarise( Count = n())
#analysis for "99"
data$var_99 = 99
data$new_var_99 = ifelse(data$var >99,1,0)
#percent of observations greater than 99 (each month)
aggregate_99 = data %>%
mutate(date = as.Date(date)) %>%
group_by(month = format(date, "%Y-%m")) %>%
summarise( mean = mean(new_var_99))
#analysis for "98"
data$var_98 = 98
data$new_var_98 = ifelse(data$var >98,1,0)
#percent of observations greater than 98 (each month)
aggregate_98 = data %>%
mutate(date = as.Date(date)) %>%
group_by(month = format(date, "%Y-%m")) %>%
summarise( mean = mean(new_var_98))
#combine files together
aggregate_98$var = 98
aggregate_98$var = as.factor(aggregate_98$var)
aggregate_99$var = 99
aggregate_99$var = as.factor(aggregate_99$var)
combine = rbind(aggregate_98, aggregate_99)
#make animation
gg <-ggplot(combine, aes(frame = var)) + geom_line(aes(x=month, y=mean, group=1))+ theme(axis.text.x = element_text(angle=90)) + ggtitle("Average Number of Observations Each Month Greater Than ....")
ggplotly(gg)
However, it seems that it is not possible to "drag" the "circular slider button" (indicated by the red arrow). It seems I can only press the "play button" and the animation autoplays. Is there a way that this code can be modified so that you can "drag" the circular slider button across?
Thanks
EDIT: my session info
> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252 LC_MONETARY=English_Canada.1252
[4] LC_NUMERIC=C LC_TIME=English_Canada.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] plotly_4.9.3 ggplot2_3.3.3 dplyr_1.0.3
loaded via a namespace (and not attached):
[1] pillar_1.4.7 compiler_4.0.3 tools_4.0.3 digest_0.6.27 jsonlite_1.7.2 lifecycle_0.2.0
[7] tibble_3.0.5 gtable_0.3.0 viridisLite_0.3.0 pkgconfig_2.0.3 rlang_0.4.10 cli_2.2.0
[13] rstudioapi_0.13 withr_2.4.1 httr_1.4.2 generics_0.1.0 vctrs_0.3.6 htmlwidgets_1.5.3
[19] grid_4.0.3 tidyselect_1.1.0 glue_1.4.2 data.table_1.13.6 R6_2.5.0 fansi_0.4.2
[25] purrr_0.3.4 tidyr_1.1.2 magrittr_2.0.1 scales_1.1.1 ellipsis_0.3.1 htmltools_0.5.1.1
[31] assertthat_0.2.1 colorspace_2.0-0 utf8_1.1.4 lazyeval_0.2.2 munsell_0.5.0 crayon_1.3.4
You should not have to change anything at all! Just click and drag. Your exact code works perfectly well on my end. And this isn't a new feature either since I'm on Package plotly version 4.9.1
in RStudio.
Click
Drag
这篇关于R/plotly:拖动滑块而不是自动播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!