Last active
April 30, 2024 04:07
-
-
Save theosanderson/57f25466cb6521f6754a6a2cf7ffd43f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file is downloaded from covid19.sanger.ac.uk with customised lineage selection | |
data<- read_csv("C:/Users/Theo/Desktop/Estimated_Cases_in_England (2).csv") | |
library(gganimate) | |
data$date | |
library(MetBrewer) | |
lookup =c("B"="Other B lineages","B.1.1.529"="Omicron", "B.1.1.7"="Alpha","B.1.617.2"="Delta","B.1.177"="B.1.177","AY.4.2"="AY.4.2") | |
library(ggrepel) | |
data$lineage | |
the_anim<- ggplot(data %>% filter(value>10,!("B.1.1.529"==lineage & date<"2021-10-20")), aes(x = date, color = lookup[lineage], y = value,group=lineage)) + | |
geom_line() + | |
theme_classic() + | |
labs(x = "Specimen date", y = "Estimated cases\n\n") + | |
theme_bw() + | |
scale_x_date(breaks = scales::pretty_breaks(6), ) + expand_limits(x=lubridate::ymd("2022-03-12"))+ | |
scale_color_brewer(type="qual") + scale_y_continuous(label=scales::comma) + coord_cartesian(ylim=c(0,NA))+ | |
labs(color = "", title = "Estimated cases per week in England by variant", caption = "Data: Wellcome Sanger Institute and UKHSA")+scale_color_manual(values=met.brewer("Juarez", 6)) + geom_label(hjust = 0,aes(label=lookup[lineage]),nudge_x=10)+ theme(legend.position = "none")+geom_point() | |
the_anim | |
data | |
anim<- the_anim + transition_reveal(date) +view_follow(fixed_y = c(0,NA),fixed_x=T) +transition_reveal(date) | |
anim | |
a <- animate(anim, renderer = file_renderer("c:/desktop/newww/"),height=500,width=800,res=140,nframes = 500,type="cairo") | |
# generates a step of PNGs that must be stitched, or you could use a different renderer that generates movies directly |
See comment on line 1 @LiXingguangBrandonStark
BTW, why you use transition_reveal(date) twice? @theosanderson
anim<- the_anim + transition_reveal(date) +view_follow(fixed_y = c(0,NA),fixed_x=T) +transition_reveal(date)
anim
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use your code to filter the lineage and date, but not work, please see below, thanks. @theosanderson