Skip to content

Handling missing rows and NAs with animated chart #1615

Open
@enuma-elis

Description

@enuma-elis

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, and/or end sooner than others. In addition even when I manually recreate the missing row with NAs, the trace containing these NAs cannot be graphed. 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')

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions