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

Area chart does not render #476

Closed
avrenli2 opened this issue Jan 26, 2023 · 3 comments
Closed

Area chart does not render #476

avrenli2 opened this issue Jan 26, 2023 · 3 comments
Labels

Comments

@avrenli2
Copy link

The animated chart does not render properly and it creates the following error messages:

Error occurred in the 1st layer.
Caused by error in unit():
'x' and 'units' must have length > 0
Problem while converting geom to grob.

library(ggplot2)
library(Rcpp)
library(gifski)
library(gganimate)
library(transformr)

library(quantmod)
CHAI <- getSymbols("SBUX" , from="2020-1-1" , to="2021-1-1" , auto.assign=F) 

CATROON <- ggplot(CHAI, aes(y=SBUX.Close,x=index(CHAI)))+
  geom_area(color="pink", size=1.2 , fill="pink" , alpha=0.3)+
  geom_point(color="#8F157E", size=4)+
  labs(x="Time", y="Close Price")+
  theme_bw() + transition_reveal(index(CHAI))  

animate(CARTOON, duration=7 , fps = 30)
@DavisVaughan
Copy link

See more information in r-lib/vctrs#1778

@thomasp85
Copy link
Owner

this is not really an issue with vectors but an incompatibility between the way gganimate works and the new stat_align()

A quick fix is to let geom_area() use stat_identity() as in the old days

CARTOON <- ggplot(CHAI, aes(y=SBUX.Close,x=index(CHAI)))+
  geom_area(color="pink", size=1.2 , fill="pink" , alpha=0.3, stat = "identity")+
  geom_point(color="#8F157E", size=4)+
  labs(x="Time", y="Close Price")+
  theme_bw() + transition_reveal(index(CHAI))  

animate(CARTOON, duration=7 , fps = 30)

@thomasp85
Copy link
Owner

This particular combination (stat_align() and transition_reveal()) now throws an error with information on how to fix it

another fix is to transition after the stat has been applied using transition_reveal(after_stat(x))

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

3 participants