-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataVisualization_Challenge1.r
61 lines (40 loc) · 1.88 KB
/
DataVisualization_Challenge1.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
library(scales)
library(tidyverse)
library(ggplot2)
library(lubridate)
library(readxl)
library(ggthemes)
library(dplyr)
covid_data_tbl <- read_csv("https://opendata.ecdc.europa.eu/covid19/casedistribution/csv")
#Table for Challenge 1 before plot
covid_data_select_tbl<- covid_data_tbl %>%
select(countriesAndTerritories,cases,dateRep,month,year,day)%>%
relocate(year,month,day)%>%
filter(year==2020,month>1) %>%
filter(day!=1)%>%
filter(countriesAndTerritories=="France"|countriesAndTerritories=="Germany"|countriesAndTerritories=="United_Kingdom"|countriesAndTerritories=="Spain"|countriesAndTerritories=="United_States_of_America")%>%
group_by(countriesAndTerritories,month)%>%
summarize(totalcases = sum(cases)) %>%
ungroup()
covid_data_select_tbl%>%
ggplot(aes(month ,totalcases, color = countriesAndTerritories)) +
geom_smooth(method = "loess", span = 0.2)+
scale_y_continuous(labels = scales::dollar_format(scale = 1/1e6,
prefix = "",
suffix = "M")) +
scale_x_continuous(breaks = seq(2, 11 , by=1),labels= c("February","March","April","May","June","July","August","September","October","November")) +
# scale_x_continuous(labels = scales::dollar_format(scale = 1/1e6,
#prefix= "",
# suffix= "February")) +
labs(
title = ("Covid-19 confirmed cases worldwide"),
subtitle = ("United States has the highest rate of cases"),
caption = "",
x = "(Year 2020)",
y = "Cumulative Cases",
color = "Country"
) +
geom_label(aes(label = (totalcases)),
hjust = "inward",
size = 3,
color = RColorBrewer::brewer.pal(n = 11, name = "RdBu")[11])