My Github Pages
by Yeung Ka Ming, CFA
COVID-19 confirmed cases by age and gender in Hong Kong
library(ggplot2)
library(tidyverse)
Download data from WHO website
enhanced_sur_covid_19_eng <- read.csv("d:/Users/ivan/Downloads/enhanced_sur_covid_19_eng.csv")
hkcovid.tbl <- as_tibble(enhanced_sur_covid_19_eng)
hkcovid1.tbl <- hkcovid.tbl %>%
mutate(Report.date = as.Date(Report.date, format = "%d/%m/%Y"),
Date.of.onset = as.Date(Date.of.onset, format = "%d/%m/%Y"))
hkcovid1.tbl %>%
group_by(Report.date) %>%
summarise(n = n()) %>%
plot(type = "l")
hkcovid2.tbl <- hkcovid1.tbl %>%
group_by(Report.date, Gender) %>%
summarise(n = n())
p <- ggplot(hkcovid2.tbl, aes(x=Report.date, y=n, color=Gender))
p+geom_line()
hkcovid2.tbl <- hkcovid1.tbl %>%
group_by(Report.date, Gender) %>%
filter(Gender == 'M' | Gender == 'F') %>%
summarise(n = n())
p1 <- ggplot(hkcovid2.tbl, aes(x=Report.date, y=n, color=Gender))
p1+geom_line(aes(linetype=Gender))+scale_size_manual(values=c(2, 2.5))
hkcovid3.tbl <- hkcovid1.tbl %>%
group_by(Age,Gender) %>%
filter(Gender == 'M' | Gender == 'F')
hkcovid4.tbl <- hkcovid3.tbl %>%
mutate(Age = as.integer(Age))
p2 <- ggplot(hkcovid4.tbl,
aes(x=Age, color=Gender, fill=Gender)) +
geom_histogram(binwidth=1, color="Black", position="identity", alpha=0.25)
p2
p3 <- ggplot(hkcovid4.tbl,
aes(x=Age, color=Gender, fill=Gender)) +
geom_histogram(binwidth=1,
color="Black",
position="identity",
alpha=0.25,
aes(y=..density..)) +
geom_density(alpha=.2, fill="#FF6666")
p3