Open
Description
Expected behavior demonstrated by geom_point. See ggplotly(gg1)
below.
Unexpected behavior when using geom_rect with the ids arg across frames with changing number of observations. See ggplotly(gg2)
and ggplotly(gg3)
below.
### Win 10 x64, Rstudio
library(ggplot2) # ggplot2_3.0.0
library(plotly) # plotly_4.7.1
data(gapminder, package = "gapminder")
# filtering out some countries (soframes have differing number of obs)
sub_countries <- unique(gapminder$country)[1:10]
gapminder2 <- gapminder %>%
filter(((year != 1952) | (country %in% sub_countries)) & year < 1970)
# using geom_point (works)
gg1 <- ggplot(gapminder2) +
geom_point(aes(x = gdpPercap, y = lifeExp,
ids = country,
frame = year)) +
scale_x_log10()
ggplotly(gg1) # correct: sub, full, full, full
# using geom_rect (doesn't work with ids arg)
gg2 <- ggplot(gapminder2) +
geom_rect(aes(xmin = gdpPercap, ymin = lifeExp,
xmax = 1.05 * gdpPercap, ymax = 1.05 * lifeExp,
ids = country,
frame = year)) +
scale_x_log10()
ggplotly(gg2) # incorrect: sub, sub, sub, sub
# using geom_rect, subset on 2nd frame (doesn't work with ids arg)
gapminder3 <- gapminder %>%
filter(((year != 1957) | (country %in% sub_countries)) & year < 1970)
gg3 <- ggplot(gapminder3) +
geom_rect(aes(xmin = gdpPercap, ymin = lifeExp,
xmax = 1.05 * gdpPercap, ymax = 1.05 * lifeExp,
ids = country,
frame = year)) +
scale_x_log10()
ggplotly(gg3) # incorrect: full, sub moves, full, full
# frame year 1952 -> 1957 != 1962 -> 1957 != 1967 -> 1957
Cheers,
Nick