R Shiny XTS-更改默认工具提示usign ggplot的名称

问题描述 投票:0回答:1

我有一个带有日期值的XTS对象,我正在使用ggplot和Shiny应用程序显示结果。但是我想在鼠标在线时更改工具提示的默认名称。

发件人:指数:2020-03-19值:70

收件人:日期:2020-03-19星期三:70

XTS代码:

data<-rnorm(10)
    dates <- seq(as.Date("2016-01-01"), length =10, by = "days")
    xtsMyData <- xts(x = data, order.by = dates)

情节:

r <- ggplot(tidy(xtsMyData), aes(x=index,y=value, color=series, type = 'scatter', mode = 'lines')
    ) + geom_line(size=2)

结果是:Default values

我正在输入以下代码:

 r <- ggplot(tidy(xtsMyData), aes(x=index,y=value, color=series, type = 'scatter', mode = 'lines')
    ) + geom_line(size=2)

    return(ggplotly(r, tooltip = **c("x","y", "series" )**) %>% plotly::config(displayModeBar = T)  %>%
             layout(legend = list(orientation = "h", x = 0.4, y = -0.2)))

结果是:

New result, it's a bit best

如何更改工具提示?我可以加词吗?我尝试了paste(“ Dates”,“ x”),但不起作用。

感谢您的帮助。

r ggplot2 shiny tooltip plotly
1个回答
0
投票

您可以使用text中的style更改悬停文本。

plotly对象将具有可通过如下列表访问的值。日期值将需要使用as.Date进行转换。

r <- ggplotly(r) %>% 
  plotly::config(displayModeBar = T) %>%
  layout(legend = list(orientation = "h", x = 0.4, y = -0.2)) 

r %>%
  style(text = paste0("Date:", as.Date(r$x$data[[1]]$x), 
                      "</br></br>", 
                      "Cantidad:", r$x$data[[1]]$y))
© www.soinside.com 2019 - 2024. All rights reserved.