0

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)

enter image description here

tomsu
  • 371
  • 2
  • 16

1 Answers1

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

enter image description here

MLavoie
  • 9,671
  • 41
  • 36
  • 56
  • Great, it is what I am looking for, thank you! I have one more question, how to remove the black border of the plot? – tomsu May 02 '18 at 21:52
  • you can play with the color (`color = "white"`) or size as in `geom_density(stat="identity", fill = "#4156C5", size = 0)`. – MLavoie May 02 '18 at 21:56