Last active
August 15, 2020 10:33
-
-
Save stephenc/563e2838c96c7e786e95378c601d304e to your computer and use it in GitHub Desktop.
Plots new cases and new deaths on same graph
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
library(tidyverse) | |
library(grid) | |
all = read.csv("owid-covid-data.csv", header = TRUE) | |
irl <- all %>% | |
filter(iso_code == "IRL") %>% | |
select(date,new_cases,new_deaths) %>% | |
mutate(date=as.Date(date, format="%Y-%m-%d")) | |
p1 <- ggplot(irl, aes(x=date,y=new_cases)) + | |
scale_x_date() + | |
ylab("New Cases") + | |
scale_y_continuous(expand = c(0, 0)) + | |
geom_col(colour=rgb(.8,.8,0),fill=rgb(.7,.7,0)) + theme(axis.title.x=element_blank(), | |
axis.text.x=element_blank(), | |
axis.ticks.x=element_blank()) | |
p2 <- ggplot(irl, aes(x=date,y=new_deaths)) + | |
xlab("Date") + | |
scale_x_date() + | |
ylab("New Deaths") + | |
scale_y_continuous(trans = "reverse", expand = c(0, 0)) + | |
geom_col(colour=rgb(.0,.8,.8),fill=rgb(0,.7,.7)) | |
g1 <- ggplotGrob(p1) | |
g2 <- ggplotGrob(p2) | |
g <- rbind(g1, g2, size="first") | |
grid.newpage() | |
grid.draw(g) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment