# Specific Date
Gyeonggi_do <- c("Asan", "Bucheon", "Goyang", "Guri", "Incheon", "Pyeongtaek", "Siheung","Suwon")
Jeollabuk_do <- c("Gunsan")
Jeollanam_do <- c("Gwangju","Naju")
Seoul <- c("Seoul")
df_corona %>%
group_by(Placeofstay) %>%
count() %>%
mutate(Province =Placeofstay) %>%
mutate(Province = case_when(Province %in% Gyeonggi_do ~ "16",
Province %in% Jeollabuk_do ~ "5",
Province %in% Jeollanam_do ~ "6",
Province %in% Seoul ~ "8",
TRUE ~ "0")) -> coronaNow
library(raster)
Korea <- getData("GADM", country = "KOR", level = 1)
# 위치 정보 가공
Korea_df <- Korea %>%
fortify(Province = "NAME_1") %>%
mutate(Province = stri_trans_general(id, "Latin-ASCII"))
# 데이터 병함
bb <- full_join(coronaNow, Korea_df, by="Province" )
my_font <- "Ubuntu Condensed"
ggplot()+
geom_polygon(data=bb, aes(long, lat, group=group, fill=n), color="grey20")+
scale_fill_viridis()+
theme(panel.grid = element_blank()) +
theme(axis.title = element_blank()) +
theme(axis.text = element_blank()) +
labs(x = NULL, y = NULL,
title = "Corona Virus in South Korea(Feb - Mar, 2020)",
caption = "Data Source: Wikipeia") +
theme(plot.title = element_text(size = 15, family = my_font, color = "gray20", face="bold")) +
theme(plot.caption = element_text(family = my_font, size = 10, colour = "grey30", face = "italic")) +
theme(legend.text = element_text(size = 10, color = "grey10", family = my_font)) +
theme_gray() -> g1
g1df_corona %>%
group_by(`VisitedWuhan?`) %>%
rename(Wuhan = `VisitedWuhan?`) %>%
count() %>%
ungroup() -> from_wuhan
kable(from_wuhan)| Wuhan | n |
|---|---|
| No | 18 |
| Yes | 12 |
from_wuhan %>%
ggplot(aes(Wuhan, n))+
geom_bar(stat= "identity",fill="#F89441FF", col="black")+
theme_economist()+
labs(x = NULL, y = "Answers",
title = "Have you been to Wuhan?")+
theme(plot.title = element_text(size = 12, family = my_font, color = "gray20", face="bold")) ->g2
g2| Nationality | n |
|---|---|
| Chinese | 6 |
| Korean | 24 |
national %>%
ggplot(aes(Nationality , n))+
geom_bar(stat= "identity",fill="#F89441FF", col="black")+
theme_economist()+
labs(x = NULL, y = "Answers",
title = "What is your Nationality?")+
theme(plot.title = element_text(size = 12, family = my_font, color = "gray20", face="bold")) ->g3
g3Question_1) All chinese are from Wuhan?
df_corona %>%
group_by(Nationality,`VisitedWuhan?` ) %>%
rename(Wuhan = `VisitedWuhan?`) %>%
summarise(count=n()) %>%
mutate(pct =count/sum(count),
lbl = scales :: percent(pct)) -> china_wuhan
kable(china_wuhan)| Nationality | Wuhan | count | pct | lbl |
|---|---|---|---|---|
| Chinese | No | 3 | 0.500 | 50.0% |
| Chinese | Yes | 3 | 0.500 | 50.0% |
| Korean | No | 15 | 0.625 | 62.5% |
| Korean | Yes | 9 | 0.375 | 37.5% |
ggplot(china_wuhan, aes(x=Nationality, y= pct, fill=Wuhan))+
geom_bar(stat = "identity", position = "fill", col="black")+
geom_text(aes(label=lbl),
size = 3,position = position_stack(vjust = 0.5))+
scale_fill_manual(values=c("#999999", "#E69F00"))+
theme_economist()+
labs(x = NULL, y = "Percent",
title = "Rate of Wuhan Visitor by Nationality?")+
theme(plot.title = element_text(size = 12, family = my_font, color = "gray20", face="bold")) -> g4
g4df_corona %>%
group_by(Gender, Placeofstay) %>%
summarise(count=n()) %>%
mutate(pct =count/sum(count),
lbl = scales :: percent(pct)) -> gender_stay
kable(gender_stay)| Gender | Placeofstay | count | pct | lbl |
|---|---|---|---|---|
| Female | Bucheon | 1 | 0.0714286 | 7.1% |
| Female | Goyang | 1 | 0.0714286 | 7.1% |
| Female | Gunsan | 1 | 0.0714286 | 7.1% |
| Female | Gwangju | 2 | 0.1428571 | 14.3% |
| Female | Incheon | 1 | 0.0714286 | 7.1% |
| Female | Seoul | 5 | 0.3571429 | 35.7% |
| Female | Siheung | 2 | 0.1428571 | 14.3% |
| Female | Suwon | 1 | 0.0714286 | 7.1% |
| Male | Asan | 2 | 0.1250000 | 12.5% |
| Male | Bucheon | 1 | 0.0625000 | 6.2% |
| Male | Goyang | 1 | 0.0625000 | 6.2% |
| Male | Guri | 1 | 0.0625000 | 6.2% |
| Male | Naju | 1 | 0.0625000 | 6.2% |
| Male | Pyeongtaek | 1 | 0.0625000 | 6.2% |
| Male | Seoul | 7 | 0.4375000 | 43.8% |
| Male | Siheung | 1 | 0.0625000 | 6.2% |
| Male | Suwon | 1 | 0.0625000 | 6.2% |
ggplot(gender_stay, aes(reorder(Placeofstay, pct) , y=pct, fill=Gender))+
geom_col(col="black")+
coord_flip()+
theme_economist()+
scale_fill_manual(values=c("#999999", "#E69F00"))+
labs(x = "Percent", y = "Province",
title = "Provinces town rate by gender",
subtitle = "Data from Feb to Mar in 2020",
caption = "Data Source: Wikipeida") +
theme(plot.title = element_text(family = my_font, size = 15, colour = "grey10")) +
theme(plot.subtitle = element_text(family = my_font, size = 10, colour = "grey20")) +
theme(plot.caption = element_text(family = my_font, size = 10, colour = "grey30", face = "italic")) +
theme(legend.text = element_text(size = 10, color = "grey10", family = my_font)) -> g5
g5df_corona %>%
group_by(Date) %>%
count() %>%
ungroup() %>%
mutate(Total = cumsum(n)) -> plot
highchart() %>%
hc_add_series(data = plot$Total,name= "The Number of Confirmed Cases",
showInLegend= FALSE, type="line") %>%
hc_yAxis(gridLineWidth = 0.6)%>%
hc_xAxis(categories = plot$Date) %>%
hc_title(text = "Accumulative Coronavirus Cases Confirmed", style = list(color = "grey20", useHTML = TRUE)) %>%
hc_chart(backgroundColor = "White")df_corona %>%
group_by(Date) %>%
mutate(encount = sum(Contactsofcase)) %>%
filter(!duplicated(Date)) %>%
na.omit() ->Encounter_bydate
Encounter_bydate$Date <- as.factor(Encounter_bydate$Date)
highchart() %>%
hc_add_series(Encounter_bydate, hcaes(x= Date, y=encount), type="line") %>%
hc_tooltip(borderWidth = 1.5,
pointFormat = paste("Encounters: <b>{point.y}</b>")) %>%
hc_xAxis(categories = Encounter_bydate$Date,
labels = list(step = 1),
min = 0, max = 12,
scrollbar = list(enabled = TRUE)) %>%
hc_title(text = "The Encounter number by dates") %>%
hc_subtitle(text = "Jan to Feb in 2020") %>%
hc_yAxis(title = list(text = "Numbers")) View(df_corona)
df_corona %>%
group_by(Date, Gender) %>%
count() %>%
ungroup() -> bygender
datatable(bygender)bygender$Date <- as.factor(bygender$Date)
sex_color <- c("#EE6AA7", "#87CEEB")
highchart() %>%
hc_add_series(bygender, hcaes(x= Date, y=n, group=Gender), type="line",
color=sex_color) %>%
hc_tooltip(crosshairs = TRUE, borderWidth = 1.5, headerFormat = "",
pointFormat = paste("Year: <b>{point.Date}</b> <br>",
"Gender: <b>{point.Gender}</b><br>",
"Cases: <b>{point.n}</b>")) %>%
hc_xAxis(categories = bygender$Date) %>%
hc_title(text = "Corona confirmed cases by Gender") %>%
hc_subtitle(text = "Jan to Feb in 2020") %>%
hc_xAxis(title = list(text = "Date")) %>%
hc_yAxis(title = list(text = "The number of cases"),
allowDecimals = FALSE,
plotLines = list(list(color = "black", width = 1, dashStyle = "Dash",
value = mean(bygender$n)))) #summary(df_corona$Age)
#Min. 1st Qu. Median Mean 3rd Qu. Max.
# 20.0 33.5 42.5 45.0 55.0 82.0
df_corona$Age_group <- ifelse(df_corona$Age >= 20 & df_corona$Age <= 40, 'Young Aged',
ifelse(df_corona$Age >= 40 & df_corona$Age <= 60, "Middle Aged",
ifelse(df_corona$Age >= 60 & df_corona$Age <= 70, "Old Aged", "Very Old")))## # A tibble: 23 x 3
## Date Age_group n
## <date> <chr> <int>
## 1 2020-01-20 Young Aged 1
## 2 2020-01-24 Middle Aged 1
## 3 2020-01-26 Middle Aged 1
## 4 2020-01-27 Middle Aged 1
## 5 2020-01-30 Middle Aged 1
## 6 2020-01-30 Young Aged 2
## 7 2020-01-31 Middle Aged 1
## 8 2020-01-31 Old Aged 1
## 9 2020-01-31 Young Aged 2
## 10 2020-02-01 Middle Aged 1
## # ... with 13 more rows
by_age$Date <- as.factor(by_age$Date)
by_age$Age_group <- as.factor(by_age$Age_group)
age_color <- rev(plasma(4))
highchart() %>%
hc_add_series(by_age, hcaes(x= Date, y=n, group=Age_group), type="line", color=age_color) %>%
hc_tooltip(crosshairs = TRUE, borderWidth = 1.5,
pointFormat = paste("Date: <b>{point.x: %Y-%m-%d}</b> <br>",
"Gender: <b>{point.Age_group}</b><br>",
"Cases: <b>{point.y}</b>")) %>%
hc_title(text="Corona confirmed cases by Age Groups") %>%
hc_subtitle(text = "Jan to Feb in 2020") %>%
hc_xAxis(title = list(text = "Date")) %>%
hc_yAxis(title = list(text = "The number of cases")) %>%
hc_xAxis(categories = c("2020-01-20", "2020-01-24",
"2020-01-26", "2020-01-27",
"2020-01-30", "2020-01-31",
"2020-02-01", "2020-02-02",
"2020-02-04", "2020-02-06",
"2020-02-09", "2020-02-10",
"2020-02-16"))지역/ 연령별 마주친 사람들 count
df_corona %>%
group_by(Placeofstay,Contactsofcase ,Age_group) %>%
filter(!duplicated(Placeofstay)) %>%
mutate(total = sum(Contactsofcase)) %>%
ungroup() %>%
na.omit()-> national_contact
datatable(national_contact)highchart() %>%
hc_add_series(national_contact, hcaes(x=factor(Placeofstay), y=total,
color=Age_group),type="bar", showInLegend = TRUE) %>%
hc_tooltip(borderWidth = 1.5,
pointFormat = paste("Total Encounter: <b>{point.y}</b>",
"Age_Group: <b>{point.Age_group}</b><br>",
"Encounters: <b>{point.y}</b>")) %>%
hc_plotOptions(column = list(stacking = "normal", borderWidth = 0.5)) %>%
hc_xAxis(categories = national_contact$Placeofstay,
labels = list(step = 1),
min = 0, max = 11,
scrollbar = list(enabled = TRUE)) %>%
hc_title(text = "The Encounter number by region and age_groups") %>%
hc_subtitle(text = "Jan to Feb in 2020") %>%
hc_yAxis(title = list(text = "Numbers"))