number instead of date on the density plot in R

不羁的心 提交于 2019-12-11 14:46:27

问题


I have a problem. I am trying to draw a density plot in R with the plotly package. But when I hover the mouse over the plot I get number format of date 17623 instead 2018-04-02. Any ideas how to solve this problem?

Date <- seq(as.Date(Sys.Date()-30), by=1, len=31)
Value <- runif(31)
dataTable <- data.frame(Date, Value)

density_plot = ggplot(dataTable, aes(x=Date, y = Value)) +
  geom_density(stat="identity", fill = "#4156C5") + 
  labs(fill = "Value", x = "Date", y = "Frequency")
ggplotly(density_plot)


回答1:


Based on this: how to choose variable to display in tooltip when using ggplotly?

You could try this:

density_plot = ggplot(dataTable, aes(x=Date, y = Value, label1= Date, label2 = Value)) +
  geom_density(stat="identity", fill = "#4156C5") + 
  labs(fill = "Value", x = "Date", y = "Frequency")

ggplotly(density_plot, tooltip = c("label1", "label2"))



来源:https://stackoverflow.com/questions/50142512/number-instead-of-date-on-the-density-plot-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!