date format in tooltip of ggplotly

前端 未结 1 1115
故里飘歌
故里飘歌 2020-12-09 09:52

I am using ggplotly to show an interactive time-series plot. The x axis is in date format, yet the hover tool tip in plotly is converting the date format to a numeric (scre

1条回答
  •  情书的邮戳
    2020-12-09 10:40

    If you use just text in your tooltip, you can render a more complex tooltip by using the text element you pass to ggplot. You just need to call as.Date and use some
    html tags as follows:

    # draw the line plot using ggplot
    gg <-ggplot(plotbycity, aes(x = date, y = rent, group = city, color = city,
        text = paste('Rent ($):', rent,
                     '
    Date: ', as.Date(date), '
    Obs: ', count))) + geom_line() + ggtitle("Monthly Rents") p <- ggplotly(gg, tooltip = c("text"))

    Hope that helps!

    0 讨论(0)
提交回复
热议问题