1

I can generate the desired ggplotly plot with the x and y aesthetics and animate using f variable for the frame. However, when I add the colour aesthetic (z) all points for all frames appear (please see plots and code below).

test dataframe:

dftest <- data.frame(
  y = c(1,10,20,50,60,1,10,20,30,45,1,10,20,40,50,1,15,25,55,60,5,15,25,35,45,5,15,25,45,50,3,6,9,18,21,1,13,16,18,30,5,15,16,18,20), 
  x = c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3), 
  z = c(20,18,16,14,12,18,17,16,14,10,18,16,14,12,8,15,14,12,8,6,18,17,16,14,10,18,16,14,12,8,20,18,16,14,12,18,17,16,14,10,18,16,14,12,8),
  f = c("a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","b","b","b","b","b","b","b","b","b","b","b","b","b","b","b","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
)

First ggplotly graph without colour, which works perfectly:

p1 <- ggplot(dftest, aes(x = factor(x), y = y))+
      geom_point(aes(size = 8, frame = f))+
      theme_bw()
ggplotly(p1)

plot 1

Then to add colour - note this was tried in both the ggplot and geom_point aesthetics

p2 <- ggplot(dftest, aes(x = factor(x), y = y, colour =z))+
      geom_point(aes(size = 8, frame = f))+
      theme_bw()
ggplotly(p2)

However, this gives all points of all frames on all frames of the plot. Note also the frame information/labels are lost.

Thanks, Philippa

plot2

Betty
  • 173
  • 1
  • 2
  • 10
  • 1
    I can't reproduce this bug. Are your package versions out-of-date? Maybe it's been fixed. – alistaire Jun 05 '20 at 00:50
  • Thanks for the reply, I've updated everything and I'm still getting the same second plot with all points on both frames – Betty Jun 05 '20 at 10:46
  • 1
    Huh, I switched back to R 3.6.3 and this reappears; on R 4.0.0 it disappears. Not sure what's actually going wrong here; it's worth opening [an issue on plotly's R package github](https://github.com/ropensci/plotly/issues) so the maintainers are aware (assuming there's not already a relevant issue). This reprex would be perfect to show what's happening. – alistaire Jun 05 '20 at 23:20
  • Ah ok, I didn't update R as I had updated it at the end of April - turns out the day before 4.0.0 was released! So yes, it does work now in R 4.0.0. So odd. Thank you so much for your help! – Betty Jun 06 '20 at 10:40

0 Answers0