R gganimate 遍历哪个组由颜色、大小、alpha 强调

R gganimate iterate through which group is emphasized by color, size, alpha

> head(data8)
# A tibble: 6 x 8
  name                industry           Time  evToGi evToRev  size alpha color  
  <chr>               <chr>              <chr>  <dbl>   <dbl> <dbl> <dbl> <chr>  
1 Activision Blizzard Gaming             Dec18   5.93    2.73     6   0.1 #777777
2 Activision Blizzard Gaming             Jun15   8.17    5.23     4   0.1 #777777
3 Adobe               Software Solutions Dec18   6.87    4.33     6   0.1 #777777
4 Adobe               Software Solutions Jun15   5.69    3.81     4   0.1 #777777
5 Amazon              Ecommerce          Dec18  39.8     6.77     6   1   #0066CC
6 Amazon              Ecommerce          Jun15  12.7     2.28     4   1   #0066CC

data8 %>%
  ggplot(aes(x = evToRev, y = evToGi, colour = industry)) +
  geom_line(aes(group = name), alpha = data8$alpha, colour = "#666666") +
  geom_point(
    size = data8$size,
    alpha = data8$alpha,
    color = data8$color) +
  labs(x = 'EV/R', y = 'EV/GM', 
       title = 'Change in EV/R and EV/GM multiples for ECommerce tech giants, 2015 - 2018')

大家好,

我有以下使用 ggplot 创建的数据和图表,我想对 10 个不同行业中的每一个进行动画处理,一次通过大小、颜色和 alpha 强调每个行业,而其他 9 个行业是变灰了。

这与示例 in the docs here 有点不同,在示例中一次显示每个虹膜组。在我的示例中,我希望始终显示所有数据,并通过更改关注的行业来简单地进行迭代。

关于如何使用 gganimate 执行此操作有任何想法吗?我目前正在处理此问题,并将根据取得的任何进展更新 post。

编辑: 我认为这将涉及一些重构,因为我无法按照目前的方式对大小、alpha 和颜色进行硬编码。 ..

我很快对此进行了测试,但它并不完全像您提到的那样工作。希望这足以让您朝着正确的方向前进。

industries <- unique(data8$industry) %>% paste(collapse = ",")

data8 <- data8 %>% 
  mutate(ind = industries) %>% 
  separate_rows(., ind, sep = ",") %>% 
  mutate(color = ifelse(ind == industry, "#0066CC", "#777777"),
     alpha = ifelse(ind == industry, 1, .1))

p <- ggplot(data8, aes(x = evToRev, y = evToGi, colour = industry)) +
  geom_line(aes(group = name, alpha = alpha), colour = "#666666") +
  geom_point(aes(alpha = alpha,
         color = color),
  size = data8$size,
  ) +
scale_alpha_identity() +
scale_color_identity() +
labs(x = 'EV/R', y = 'EV/GM', 
    title = 'Change in EV/R and EV/GM multiples for ECommerce tech giants, 2015 - 2018') 

anim <- p + transition_states(ind)

anim