0

I'm using ggplotly in a shinyApp. The application works fine with ggplotly for normal graphs. However, when I tried to add animation to the graph, the graph only showed movements of the points not the whole graph. The code is running without errors but not showing the main graph. I suspect the issue could be from frame argument. Please note that if you add aes(frame=F) to geom_point in below code it will work but not in ggplotly inside shinyApp.

here is my MWE:

x<-structure(list(A = c(0L, 0L, 0L, 0L, 0L), B = c(5L, 6L, 15L, 
                                                   17L, 2L), C = c(0L, 0L, 0L, 0L, 0L), D = c(0L, 0L, 0L, 0L, 0L
                                                   ), E = structure(c(18316, 18317, 18318, 18319, 18320), class = "Date"), 
                  F = c(5L, 11L, 26L, 43L, 45L)), row.names = c(NA, 5L), class = "data.frame")

gp<-ggplot(data = x,
           aes(x = E, y = F, frame=F)) +
  geom_line( color="red") +
  geom_point(shape=21, color="red", fill="#69b3a2", size=4) +
  theme(axis.text.x = element_text(color="#993333",
                                   size=10, 
                                   angle=45,
                                   hjust = 1),
        axis.text.y = element_text(color="#993333",
                                   size=10,
                                   angle=45,
                                   hjust = 1)
  ) +

  scale_x_date(date_labels = "%b/%d" )


#+show(gp)

ggplotly(gp)

Any suggestions ?

SimpleNEasy
  • 879
  • 3
  • 11
  • 32

1 Answers1

0

I don't think you can convert multiple frames (animation plot) into ggplotly at this time. Also, in the above example, there is not enough data to show multiple frames. My suggestion would be to build the first frame with plot_ly and then add_trace (I know, it is a hack) for subsequent frames. Highest number of items should be in the first frame. While it is not an elegant solution, it will get the job done.

YBS
  • 19,324
  • 2
  • 9
  • 27