gganimate не будет показывать след к движущимся точкам - PullRequest
1 голос
/ 28 июня 2019

Я пытаюсь создать анимацию созданного мною ggplot, но он не создает след с использованием transition_time, я читал и видел, как люди используют transition_reveal, но получаю это сообщение об ошибке

Ошибка в png :: readPNG (кадры 1 , собственный = ИСТИНА): невозможно открыть /var/folders/_z/y8zrlqwj4fs2wgkxyrztvqhr0000gn/T//Rtmp2zZJvG/1a492ff72039/gganim_plot0001.png Кроме того: было 50 или более предупреждений (используйте предупреждения (), чтобы увидеть первые 50)

ниже GIF с функцией transition_time

enter image description here

в последнем кадре я пытаюсь сделать так, чтобы он выглядел как оригинальный ggplot, который я сделал здесь ниже

enter image description here

вот часть моих данных

library(ggplot2)
library(dplyr)
library(gganimate)

RCT_NIH_mod <- structure(list(Year.Published = c(1993, 1993, 1993, 1993, 1993, 
1993, 1993, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1995, 1995, 
1995, 1995, 1995, 1995, 1995), group = structure(c(2L, 3L, 4L, 
5L, 6L, 1L, 7L, 2L, 3L, 4L, 5L, 6L, 1L, 7L, 2L, 3L, 4L, 5L, 6L, 
1L, 7L), .Label = c("Mino", "Alaska", "Asia", 
"Lack", "Islander", "Patino", "Native"
), class = "factor"), numPapers = c(791L, 791L, 791L, 791L, 791L, 
791L, 791L, 991L, 991L, 991L, 991L, 991L, 991L, 991L, 1129L, 
1129L, 1129L, 1129L, 1129L, 1129L, 1129L), numMentions = c(0L, 
1L, 17L, 0L, 4L, 22L, 1L, 0L, 4L, 13L, 0L, 8L, 26L, 0L, 0L, 8L, 
31L, 0L, 8L, 54L, 7L), freqMentions = c(0, 0.00126422250316056, 
0.0214917825537295, 0, 0.00505689001264223, 0.0278128950695322, 
0.00126422250316056, 0, 0.00403632694248234, 0.0131180625630676, 
0, 0.00807265388496468, 0.0262361251261352, 0, 0, 0.0070859167404783, 
0.0274579273693534, 0, 0.0070859167404783, 0.0478299379982285, 
0.00620017714791851)), row.names = c(NA, -21L), class = c("tbl_df", 
"tbl", "data.frame"))
Graph_NIH_anim <- RCT_NIH_mod %>%
  ggplot(aes(x = Year.Published, y = freqMentions, group = group)) + 
    geom_line() +
    geom_point(aes(shape = group)) +
    scale_x_continuous(breaks = min(RCT_NIH_mod$Year.Published):max(RCT_NIH_mod$Year.Published)) +
    scale_y_continuous(breaks = seq(0, .1208, .02),
                     labels = scales::percent_format(accuracy = 1), 
                     limits = c(0, .1208)) +
    scale_shape_manual(values = 1:nlevels(RCT_NIH_mod$group), 
                       breaks = c("Mino", "Alaska", "Asia", 
"Lack", "Islander", "Patino", "Native"), 
                       labels = c("1", "2", "3", "4s", "5", "6", "7") ) +
    theme_classic() +
    theme(legend.title = element_blank()) +
                      xlab('!') +
                      ylab('  (%)') +
    theme(axis.text.x=element_text(angle=45,hjust=1)) + 
    theme(panel.border = element_blank(),
          axis.line= element_line(colour="black")) + 
    theme(legend.position = c(.16,.78)) +
    theme(legend.background = element_blank()) + 
    ggtitle("!") +
    transition_reveal(RCT_NIH_mod$Year.Published) +
    labs(title = "Year: {frame_time}") 
Graph_NIH_anim

1 Ответ

3 голосов
/ 28 июня 2019

Замените две последние строки на transition_reveal(Year.Published) + labs(title = "Year: {round(frame_along, 0)}"), и я получаю анимацию ниже.Как и вызов aes() в ggplot2, термины transition_* ищут имя столбца без таблицы и $, а transition_reveal имеет вычисляемые переменные, отличные от transition_time.

enter image description here

...