1

Say you have the following df:

x <- as.Date(c("1963-06-01", "1964-06-01", "1965-06-01","1966-06-01"))
y <- c(1162.7, 975.4, 1280.3, 1380.0)
data<- data.frame(x, y)

when you plot it using ggplot, everything seems to work:

ggplot(data = data, aes(x = x, y = y)) +
      geom_bar(stat = "identity")

ggplot works

However, if we add a ggplotly wrap around it, the graph disappears.

ggplotly(ggplot(data = data, aes(x = x, y = y)) +
      geom_bar(stat = "identity"))

ggplotly doesn't work

I get a warning message that says:

We recommend that you use the dev version of ggplot2 with ggplotly().

Now, if I remove the date format, the gglotly does work.

x <- c("1963-06-01", "1964-06-01", "1965-06-01","1966-06-01")
y <- c(1162.7, 975.4, 1280.3, 1380.0)
data<- data.frame(x, y)

ggplotly(ggplot(data=data) + 
  geom_bar(aes(x = x, y = y), stat = "identity"))

So, there seems to be an issue with ggplotly handling geom_bar with dates. Is there a way to solve this?

  • The basic `geom_bar` example from *plotly* shown [here](https://plot.ly/ggplot2/geom_bar/) works fine for me. The code you include doesn't look like it could have made the plots you show. If the plotly example works for you, try adding an example of your actual data and plotting code. – aosmith Jul 05 '17 at 17:18
  • Just edited the question and added more specific information. The problem seems to arise only when I give ggplotly a date column. – Camila Vargas Restrepo Jul 06 '17 at 19:20
  • Can you add info about your system to the question? I tried it with Windows 10, `plotly_4.5.6.9000`, `ggplot2_2.2.1` and it worked. – Maximilian Peters Jul 06 '17 at 19:26
  • Sure, I am working on: macOs Sierra, plotly version 4.7.0, ggplot2 version 2.2.1 R version 3.4.0 (2017-04-21) – Camila Vargas Restrepo Jul 06 '17 at 19:32

1 Answers1

1

This appears to be a problem in Mac and seems to be related with the way geom_bar handles dates.

I found that adding as.POSIXct() fixes the issue.

x <- c("1963-06-01", "1964-06-01", "1965-06-01","1966-06-01")
y <- c(1162.7, 975.4, 1280.3, 1380.0)
data<- data.frame(x, y)

ggplotly(ggplot(data=data) + 
  geom_bar(aes(x = as.POSIXct(x), y = y), stat = "identity"))