Corona Visualzation

DOEUN

2020 4 10

link1 %>% 
  read_csv() %>% 
  rename(province = `Province/State`, country = `Country/Region`) %>% 
  gather(Date, Confirmed, -province, - country, - Lat, -Long) %>% 
  mutate(Date = mdy(Date)) -> df_global

start <- ymd("2020-02-28")
listnara <- c("US", "UK", "South Korea", "China", "France", "Italy")


df_global %>% 
  mutate(country = as.character(country)) %>% 
  mutate(country = case_when(country == "United States" ~ "US", 
                             country == "United Kingdom" ~ "UK",
                             country == "Korea, South" ~ "South Korea",
                             TRUE ~ country)) %>% 
  select(country, Date, Confirmed) %>% 
  filter(Date > start) %>% 
  filter(country %in% listnara) -> df_clean_one


df_clean_one %>% 
  group_by(country, Date) %>%  
  summarise(Confirmed = sum(Confirmed)) %>% 
  mutate(Thousand = round(Confirmed/1000,0)) %>% 
  ungroup() -> Cleaned_data

#summary(Cleaned_data$Thousand) (0,461)

my_colors <-  c("#04536e", "#7c2817", "#f15c42", "#3d6a51", "#eca324", "#12a4dc")

my_font <- "Ubuntu Condensed"

#---------- labelling 

savepoint <- ymd("2020-04-06")

Cleaned_data %>% 
  filter(Date == savepoint) %>% 
  filter(!duplicated(country)) -> label_df


#_______________________ Stage 구분 


stage_from_one <- ymd("2020-03-13")
stage_to_one <- ymd("2020-03-17")

stage_from_two <- ymd("2020-03-27")
stage_to_two <- ymd("2020-03-31")

Cleaned_data %>%  
  mutate(Stages  = case_when(Date >= stage_from_one & Date <= stage_to_one ~ "Wave ONe",
                             Date >= stage_from_two & Date <= stage_to_two ~ "Wave Two", TRUE ~ "no wave")) -> Wave_df


#_________________ 시각화 

ggplot(Cleaned_data, aes(Date, Thousand, group= country, color= country))+
  geom_rect(aes(xmin = stage_from_one, xmax = stage_to_one, ymin = 0, ymax = Inf),
              fill = "white", col= "white",alpha = 0.3, show.legend = FALSE) +
   geom_rect(aes(xmin = stage_from_two, xmax = stage_to_two, ymin = 0, ymax = Inf),
              fill = "white", col= "white",alpha = 0.3, show.legend = FALSE)+
  annotate("Text", label = "WAVE ONE", x= ymd("2020-03-15"), y= 450, size=3.0, 
           face= "bold", color = "Black", family= my_font)+
  annotate("Text", label = "WAVE TWO", x= ymd("2020-03-29"), y= 450, size=3.0, 
           face= "bold", color = "Black", family= my_font)+
  geom_line(size= 1.2, show.legend = FALSE)+
  geom_text(data=label_df, aes(Date, Thousand, label=country),
            show.legend = FALSE, family = my_font, size=4.5,face= "bold", 
            hjust=0, vjust= 0.5)+
  scale_y_continuous(limits = c(0,470))+
  scale_color_manual(values = my_colors )+
  theme(panel.background = element_rect(fill = "grey90" ))+
  theme(plot.background = element_rect(fill ="grey90"))+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank())+
  annotate("pointrange", x = ymd("2020-03-05"), y = 0, ymin = 0, ymax = 25,
  colour = "darkgreen", size = 0.5)+
  annotate("text", label= "First UK Death", x = ymd("2020-03-05"), y = 30, 
  colour = "darkgreen", size = 3.5)+
  annotate("text", label= "Lockdown in UK", 
             x = ymd("2020-03-23"), y = 200, 
  colour = "Black", size = 3.5)+
    annotate("pointrange", x = ymd("2020-03-23"), y = 0, ymin = 0, ymax = 190,
  colour = "Black", size = 0.5)+
    labs(x= "Date", y= "Confirmned Corona Case (in Thousand)",title = "The Number of COIVD-19 Cases Continue to Increase",
       subtitle = "Global Corona - March to Now",
       caption = "Data Source : Open source of github")+
  theme(text = element_text(family = my_font, size = 12, color = "gray30"))+ 
  theme(plot.caption = element_text(size = 11, color = "grey40", family = my_font, 
                                    face = "bold"))+ 
  theme(plot.title = element_text(size= 15, face= "bold"))+
  theme(plot.subtitle = element_text(color = "gray30", size = 10, family = my_font))+
  theme_fivethirtyeight()

##   [1] "Italy"       "South Korea" "US"          "Italy"       "South Korea"
##   [6] "US"          "Italy"       "South Korea" "US"          "Italy"      
##  [11] "South Korea" "US"          "Italy"       "South Korea" "US"         
##  [16] "Italy"       "South Korea" "US"          "Italy"       "South Korea"
##  [21] "US"          "Italy"       "South Korea" "US"          "Italy"      
##  [26] "South Korea" "US"          "Italy"       "South Korea" "US"         
##  [31] "Italy"       "South Korea" "US"          "Italy"       "South Korea"
##  [36] "US"          "Italy"       "South Korea" "US"          "Italy"      
##  [41] "South Korea" "US"          "Italy"       "South Korea" "US"         
##  [46] "Italy"       "South Korea" "US"          "Italy"       "South Korea"
##  [51] "US"          "Italy"       "South Korea" "US"          "Italy"      
##  [56] "South Korea" "US"          "Italy"       "South Korea" "US"         
##  [61] "Italy"       "South Korea" "US"          "Italy"       "South Korea"
##  [66] "US"          "Italy"       "South Korea" "US"          "Italy"      
##  [71] "South Korea" "US"          "Italy"       "South Korea" "US"         
##  [76] "Italy"       "South Korea" "US"          "Italy"       "South Korea"
##  [81] "US"          "Italy"       "South Korea" "US"          "Italy"      
##  [86] "South Korea" "US"          "Italy"       "South Korea" "US"         
##  [91] "Italy"       "South Korea" "US"          "Italy"       "South Korea"
##  [96] "US"          "Italy"       "South Korea" "US"          "Italy"      
## [101] "South Korea" "US"          "Italy"       "South Korea" "US"         
## [106] "Italy"       "South Korea" "US"          "Italy"       "South Korea"
## [111] "US"          "Italy"       "South Korea" "US"          "Italy"      
## [116] "South Korea" "US"
## # A tibble: 117 x 4
##    country Date       Confirmed hundred
##    <chr>   <date>         <dbl>   <dbl>
##  1 Italy   2020-03-02      2036      20
##  2 Italy   2020-03-03      2502      25
##  3 Italy   2020-03-04      3089      31
##  4 Italy   2020-03-05      3858      39
##  5 Italy   2020-03-06      4636      46
##  6 Italy   2020-03-07      5883      59
##  7 Italy   2020-03-08      7375      74
##  8 Italy   2020-03-09      9172      92
##  9 Italy   2020-03-10     10149     101
## 10 Italy   2020-03-11     12462     125
## # ... with 107 more rows
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    65.0   217.5   880.0  1745.5  2885.0  6155.0