【问题标题】:Is it possible to customize plotly rangeslider in R?是否可以在 R 中自定义绘图范围滑块?
【发布时间】:2021-04-25 02:58:00
【问题描述】:

快速说明:我也在R Studio Community 上发布了这个问题。

我正在尝试修改一个绘图滑块,使其成为类似于此处的范围滑块:

rangeslider() 函数的问题在于,它生成的不是像图像中那样的范围滑块,而是生成一个本质上是主图的子图:

dat<- data.frame(y=rnorm(366, mean=100, sd=50),
                 x=seq(as.Date("2020-01-01"), as.Date("2020-12-31"), by="days"))
p1<- dat %>% 
  ggplot(aes(x=x, y=y)) +
  geom_col() +
  theme_minimal() +
  xlab("") + ylab("") 
ggplotly(p1, tooltip="x", dynamicTicks = TRUE) %>% rangeslider()

.

我已经设法在 ggplot 的美学中使用frame = 获得了一个更类似于我想要的样式的滑块,但是生成的滑块一次只选择一个值而不是它们的范围:

dat<- data.frame(y=rnorm(366, mean=100, sd=50),
                 x=seq(as.Date("2020-01-01"), as.Date("2020-12-31"), by="days"))
p1<- dat %>% 
  ggplot(aes(x=x, y=y, frame=as.character(x))) +
  geom_col(position="dodge2") +
  theme_minimal() +
  xlab("") + ylab("") 
ggplotly(p1, tooltip="x")

.

是否可以用我想要的样式创建一个范围滑块?对于如何解决此问题的任何建议,我将不胜感激。

【问题讨论】:

    标签: r ggplot2 plotly r-plotly rangeslider


    【解决方案1】:

    不幸的是,内置的 Plotly 滑块只有一个“手柄”,因此无法表示范围。

    【讨论】:

    • 我已经设计了一种使用串扰的 filter_slider() (rpubs.com/LucasT/715872) 的解决方案,但是当以与 range_slider() 相同的方式选择范围时,这不会放大图形。
    • 那么如何将 Rangeslider 形式的 Shiny 连接到一个有情节的情节?那可行吗?请参阅我的问题:stackoverflow.com/questions/70392086/…
    猜你喜欢
    • 2016-07-24
    • 1970-01-01
    • 2019-03-29
    • 1970-01-01
    • 2021-10-27
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 2015-10-16
    相关资源
    最近更新 更多