我正在使用 ggplotly 显示交互式时间序列图。x 轴是日期格式,但 plotly 中的悬停工具提示正在将日期格式转换为数字(附截图)。关于如何让日期在工具提示中显示为正确日期的任何想法?
下面是一小段代码:
output$ggplot <- renderPlotly({
plotbycity<-df_postgres %>% group_by(city, date, bedroooms) %>%
filter(city %in% input$checkGroup & bedroooms==input$radio) %>%
summarise(count=n(),rent=median(rent)) %>%
ungroup()
plotbycity$date<-as.Date(plotbycity$date)
# Error handling
plotbycity<-plotbycity[!is.na(plotbycity$city),]
if (is.null(plotbycity)) return(NULL)
#plotbycity<-ungroup(plotbycity)
#dat <- dat[c("rent", "bedroooms", "date", "City")]
#dat <- melt(dat,id.vars=c("date", "City", "bedroooms"),na.rm=TRUE) #
# draw the line plot using ggplot
gg <-ggplot(plotbycity, aes(x = date, y = rent, group = city, color = city,
text = paste('obs: ', count))) +
geom_line() +
ggtitle("Monthly Rents")
# #theme_hc(bgcolor = "darkunica") +
# #scale_fill_hc("darkunica")
p <- ggplotly(gg, tooltip = c("x", "y", "text"))