R中的密度图上的数字而不是日期 [英] number instead of date on the density plot in R

查看:100
本文介绍了R中的密度图上的数字而不是日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题.我正在尝试使用plotly包在R中绘制密度图.但是,当我将鼠标悬停在图上时,我得到的是日期为17623的数字格式,而不是2018-04-02.有什么想法可以解决这个问题吗?

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)

推荐答案

基于此:您可以尝试以下方法:

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"))

这篇关于R中的密度图上的数字而不是日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆