-
Notifications
You must be signed in to change notification settings - Fork 0
/
covid.R
109 lines (97 loc) · 3.49 KB
/
covid.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Load libraries
library(tidyverse)
library(scales)
library(lubridate)
library(gganimate)
library(gifski)
covid <- read_csv("time-series-19-covid-combined.csv")
# Remove unnecessary Columns and Rename
covid <- covid %>%
select(Date, country = `Country/Region`, Confirmed, Recovered, Deaths)
# Create a useful data frame
covid_stat <- covid %>%
group_by(country) %>%
summarise(Death = max(Deaths), Confirmed = max(Confirmed), Recovered = max(Recovered)) %>%
mutate(Active_case = Confirmed - Recovered)
# top 10 Confirmed
covid_stat %>%
arrange(desc(Confirmed)) %>%
top_n(10) %>%
ggplot(aes(x = reorder(country, -Confirmed), y = Confirmed, fill = country)) +
geom_bar(stat = "identity") +
scale_y_continuous(labels = comma) +
ggtitle("Top 10 Total Confirmed")
# Top 10 Deaths
covid_stat %>%
arrange(desc(Death)) %>%
top_n(10) %>%
ggplot(aes(x = reorder(country, -Death), y = Death, fill = country)) +
geom_bar(stat = "identity") +
scale_y_continuous(labels = comma) +
ggtitle("Top 10 Total Deaths")
# Top 10 Recovered
covid_stat %>%
arrange(desc(Recovered)) %>%
top_n(10) %>%
ggplot(aes(x = reorder(country, -Recovered), y = Recovered, fill = country)) +
geom_bar(stat = "identity") +
scale_y_continuous(labels = comma) +
ggtitle("Top 10 Total Recovered")
# Top 10 Active Cases
covid_stat %>%
top_n(10) %>%
ggplot(aes(x = reorder(country, Active_case), y = Active_case, fill = country)) +
geom_bar(stat = "identity") +
coord_flip() +
scale_y_continuous(labels = comma) +
ggtitle("Top 10 Total Active Case")
# animated graph Total death India (Line Graph)
p1 <- covid %>%
group_by(country, Date) %>%
summarise(Death = max(Deaths), Confirmed = max(Confirmed), Recovered = max(Recovered)) %>%
arrange(desc(Death)) %>%
filter(country == "India") %>%
ggplot(aes(Date, Death)) +
ggtitle("Total Death In India") +
geom_line(color = "blue") +
scale_y_continuous(labels = comma) +
geom_point(size = 1.5) +
transition_reveal(Death)
animate(p1, height = 600, width = 800, fps = 30, duration = 10, end_pause = 60, res = 100)
anim_save("india.gif")
# Animated Graph Multiple Countries (Line Graph)
p2 <- covid %>%
group_by(country, Date) %>%
summarise(Death = max(Deaths), Confirmed = max(Confirmed), Recovered = max(Recovered)) %>%
arrange(desc(Confirmed)) %>%
filter(country == "India" |
country == "US" |
country == "Brazil" |
country == "Russia") %>%
ggplot(aes(Date, Confirmed, color = country)) +
ggtitle("Confirmed Cases") +
geom_line() +
scale_y_continuous(labels = comma) +
geom_point(size = 1.5) +
transition_reveal(Confirmed)
animate(p2, height = 600, width = 800, fps = 30, duration = 10, end_pause = 60, res = 100)
anim_save("all confirmed.gif ")
# Animated Graph total death multiple Countries (Bar plot)
p3 <- covid %>%
group_by(country, Date) %>%
summarise(Death = max(Deaths), Confirmed = max(Confirmed), Recovered = max(Recovered)) %>%
arrange(desc(Confirmed)) %>%
filter(country == "India" |
country == "US" |
country == "Brazil" |
country == "Russia") %>%
ggplot(aes(x = reorder(country, -Death), y = Death, fill = country)) +
geom_bar(stat = "identity") +
scale_y_continuous(labels = comma) +
transition_time(Date) +
labs(
title = "Animated Bar Graph",
subtitle = "Day : {frame_time}"
)
animate(p3, height = 600, width = 800, fps = 30, duration = 10, end_pause = 60, res = 100)
anim_save("bar.gif")