Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble Animating Simple Line Graph After Multiple Attempts #466

Closed
miguelbp22 opened this issue Aug 23, 2022 · 1 comment
Closed

Trouble Animating Simple Line Graph After Multiple Attempts #466

miguelbp22 opened this issue Aug 23, 2022 · 1 comment
Labels

Comments

@miguelbp22
Copy link

Hey Thomas,

Firstly, thanks for creating such a cool and powerful library - just discovered it and having a lot of fun with it.

However, I've come across some issues that I can't seem to get around and I'm not sure why my animations aren't rendering or how to get around them. The short of it it, I have a pretty simple and small dataframe that plots just fine on ggplot2, but once I try and animate, I get errors depending on my attempt that's usually in this form:

  1. "Error in rep(seq_len(nrow(polygon)), splits + 1) :
    invalid 'times' argument"

And the only way I was able to render it, it was faulty and came up w several warnings about each group consists of only one observation, ultimately looking like this, without the actual line graph:

error_animation

I'm attaching my (very simple) code here, as well as the data in case you'd like to reproduce yourself. Any thoughts as to why this isn't working? I have some big ideas to use this library for my job, so any help would be hugely appreciated!

btw - I don't understand why this isn't working now as I got it to work before on a different (but pretty similar) data set:
nba_test

top-fundraisers.csv

top <- read.csv('top-fundraisers.csv')

#renaming a column, filtering for only US and excluding unnecessary vars
top_us <- top %>% rename(dollars = X.dollars) %>% filter(fundraiser_country == 'US') %>% select(-c(dollars_excl_refund, campaign_id))

#formatting date to date class and extracting year
top_us$creation_date = as.Date(top_us$creation_date, format="%m/%d/%y")
top_us$year = format(top_us$creation_date,"%Y")

#converting the dollars amount from str to numeric
top_us$dollars <- as.numeric(gsub(",","",top_us$dollars))

#extracting top fundraiser by year
top_us_year <- top_us %>% group_by(year) %>% slice_max(order_by = dollars, n = 1) %>% as.data.frame()

###attempt #1
top_g <- ggplot(top_us_year, aes(x = creation_date, y = dollars, group = fundraiser_country)) + 
  geom_line() + geom_point() + transition_time(creation_date)
animate(top_g)
###ERROR:
#Error in rep(seq_len(nrow(polygon)), splits + 1) : 
#  invalid 'times' argument

###attempt #2
top_g <- ggplot(top_us_year, aes(x = creation_date, y = dollars, group = fundraiser_country)) + 
  geom_line(aes(group=creation_date), linetype=1)  + geom_point() + transition_time(creation_date)
animate(top_g)
###ERROR:
#geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
#  geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
#  Rendering [==========================>---------------------------------------------------] at 13 fps ~ eta:  5sgeom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?

###attempt #3
top_g <- ggplot(top_us_year, aes(x = year, y = dollars, group = fundraiser_country)) + 
  geom_line()  + geom_point() + transition_states(year)
animate(top_g)
###ERROR:
#Error in rep(seq_len(nrow(polygon)), splits + 1) : 
#invalid 'times' argument

###attempt #4
top_g <- ggplot(top_us_year, aes(x = year, y = dollars, group = fundraiser_country)) + 
  geom_line(aes(group=year))  + geom_point() + transition_states(year)
animate(top_g)
###ERROR:
#Error in `vec_rbind()`:
#! Can't combine `..1$x` <mapped_discrete> and `..2$x` <mapped_discrete>.
#✖ Some attributes are incompatible.
#ℹ The author of the class should implement vctrs methods.
#ℹ See <https://vctrs.r-lib.org/reference/faq-error-incompatible-attributes.html>.
@thomasp85 thomasp85 added the bug label Aug 30, 2023
@thomasp85
Copy link
Owner

I believe this is fixed in the dev version. There has been quite a few regressions related to switching to vctrs but they have been cleaned up now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants