-
Notifications
You must be signed in to change notification settings - Fork 308
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
Using {frame_time} in the title for year shows non-integers #295
Comments
I figured this out. If the numeric value being used, ie year, is type double, you will get this behavior. If it is type integer, it works correctly. If this isn't intended, might be good to treat variables that could be integer as integer. Example: library(gapminder)
library(gganimate)
#> Loading required package: ggplot2
library(tidyverse)
gapminder %>%
mutate(year = as.numeric(year)) %>%
ggplot(aes(gdpPercap, lifeExp, size = pop, colour = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
facet_wrap(~continent) +
# Here comes the gganimate specific bits
labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
transition_time(year) +
ease_aes('linear') Created on 2019-02-19 by the reprex package (v0.2.1) |
The solution, I read elsewhere, is to change your year variable to integer, and then, instead of
|
No need for that — just put |
But, if I need to show not year (like 2012, 2013 etc), but period (2012-1, 2012-2 etc). How to do that? |
However you’d usually do this with R code. You can basically stick whatever code inside |
Simple solution is to use |
Hello, I think I have a similar problem, I want to add evolving date and time(minutes) to the title of my ggplot animate, |
When I use transition_time(year) and put "year: {year}" in the title, I get titles like "2017.285183", "2017.486" etc, building up through non-integers.
The text was updated successfully, but these errors were encountered: