I'm trying to create an animation of a ggplot I made, but it doesn't create a trail using transition_time, I've read and seen people use transition_reveal but get this error message
Error in png::readPNG(frames1, native = TRUE) : unable to open /var/folders/_z/y8zrlqwj4fs2wgkxyrztvqhr0000gn/T//Rtmp2zZJvG/1a492ff72039/gganim_plot0001.png In addition: There were 50 or more warnings (use warnings() to see the first 50)
below is the gif with function transition_time
at the final frame i'm trying to make it look like the original ggplot that i made here below
here is a portion of my data
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
Replace the last two line with transition_reveal(Year.Published) + labs(title = "Year: {round(frame_along, 0)}")
, and I get the animation below. Like the aes()
call in ggplot2
, the transition_*
terms are looking for a column name with out the table and $
, and transition_reveal
has different calculated variables than transition_time
.