Plotly: handling missing values with animated chart

Hi.
I found out that when using animated plotly chart you need to have the same number of observations for each of your factors. Meaning -> one missing observation results in whole trace being discarded for entire duration of the animated chart. That is especially a problem when you use time-series data and some of your traces start later, or end sooner than others. Is there any workaround beside of imputing null values for the missings? Thanks!

Example:

library(gapminder)
library(plotly)
library(dplyr)

#working example with no missings
gapminder %>% 
  group_by(year, continent) %>% 
  summarise(pop = mean(pop), gdpPercap = mean(gdpPercap), lifeExp = mean(lifeExp)) %>%
  plot_ly( x = ~gdpPercap, 
           y = ~lifeExp, 
           size = ~pop, 
           color = ~continent, 
           frame = ~year, 
           text = ~continent, 
           hoverinfo = "text",
           type = 'scatter',
           mode = 'markers')

#filtering one row results in missing Africa trace for entirety of the plot

gapminder %>% 
  group_by(year, continent) %>% 
  summarise(pop = mean(pop), gdpPercap = mean(gdpPercap), lifeExp = mean(lifeExp)) %>%
  filter(gdpPercap > 1253) %>% 
  plot_ly( x = ~gdpPercap, 
           y = ~lifeExp, 
           size = ~pop, 
           color = ~continent, 
           frame = ~year, 
           text = ~continent, 
           hoverinfo = "text",
           type = 'scatter',
           mode = 'markers')

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.