Hello everyone,
I have a dataframe that has daily data about Covid19 (such as: total_cases,total_deaths) in some European countries (there are 49 countries in total). You can have the whole dataframe here. I want to create a Bar Chart Race for the variable total_cases for all the European countries with ggplot. So, I followed the steps from this link and I wrote the below code:
library(ggplot2)
g1 = ggplot(data = data.europe,
aes(x = as.Date(date),y = total_cases,group = location,
color = location)) + geom_line(size = 0.5) +
labs(y = "Total Cases", x = "Date") +
theme(legend.position = "bottom",legend.box = "vertical",
legend.title = element_blank(),
legend.text = element_text(size = 10))
Then I wrote the below code in order to create the dynamic plot
g1_star = ggplot(data = data.europe,
aes(x = as.Date(date),y = total_cases,group = location,
color = location)) + geom_line(aes(group = as.Date(date)),linetype=1) +
labs(y= "Total Cases", x = "Date") +
theme(legend.position = "bottom",legend.box = "vertical",
legend.title = element_blank(),
legend.text = element_text(size = 10)) +
transition_reveal(as.Date(date))
#We wil create the an animation
library(gifski)
library(gganimate)
animate(g1_star,height= 538,width = 866)
data_star = data.europe %>% group_by(as.Date(date))
However when I wrote these lines:
g1_star_anim = ggplot(data_star,aes(x = as.Date(date),
y = total_cases,
group = location,
fill = location,
color = location)) +
geom_tile(aes(height = total_cases,width = 0.9), alpha = 0.8,color = NA) +
geom_text(aes(y = 0, label = paste(location, " ")), vjust = 0.2, hjust = 1) +
scale_y_continuous(labels = scales::comma) + theme(axis.line=element_blank())
anim1 = g1_star_anim + transition_states(as.Date(date), transition_length = 4,
state_length = 1) +
view_follow(fixed_x = TRUE) +
labs(title = 'Total_cases per year')
The result is:
which isn't expected.
What should I change? Or which code should I write? Can anyone help me because I have been searching for a very long time?
Thanks in advance!