-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonkeypox2022_v1.0.2.R
139 lines (119 loc) · 4.02 KB
/
monkeypox2022_v1.0.2.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
library(shiny)
library(ggplot2)
library(dplyr)
library(maps)
wmap <- map_data("world")
wmap$region <- recode(wmap$region,
"USA" = "United States",
"UK" = "England")
file_url <-
"https://raw.githubusercontent.com/globaldothealth/monkeypox/main/latest_deprecated.csv"
mpoxdat <- subset(read.csv(file_url,
header = TRUE,
na.strings = c("", ".", "NA")),
Status %in% "confirmed") %>%
mutate(Date_confirmation = as.Date(Date_confirmation))
mpoxdat1 <- mpoxdat %>%
group_by(Country) %>%
summarize(n = n()) %>%
arrange(desc(n)) %>%
ungroup()
#################################################################################
ui <- fluidPage(
sliderInput("topx", "Top N Countries:", min = 1, max = 15, value = 10),
textOutput("count"),
plotOutput("plot"),
plotOutput("plot1"),
plotOutput("plot2")
)
server <- function(input, output, session) {
output$count <- renderText({
paste("Total number of confirmed world-wide cases, as of",
paste0(format(max(mpoxdat$Date_confirmation), "%a %b %d %X %Y"), ","),
"is",
nrow(mpoxdat))
})
top_list <- reactive(
mpoxdat1 %>%
top_n(input$topx, n) %>%
mutate(
Country1 = Country
) %>%
select(-c("n"))
)
mpoxdat2 <- reactive(
merge(x = mpoxdat,
y = top_list(),
by = "Country",
all.x = TRUE) %>%
mutate(
Region = ifelse(!is.na(Country1), Country, "Rest of The World")
)
)
output$plot <- renderPlot({
ggplot(mpoxdat2(),
mapping = aes(x = Region)) +
geom_text(stat = "count", aes(label = ..count..), vjust = -1) +
ylim(0, max(mpoxdat1$n) + 500) +
labs(
title = "Monkeypox cases by Country",
subtitle = "Algorithm Basics Infographics",
x = "Country/Region",
y = "Number of Confirmed Cases"
) +
geom_bar(aes(fill = Region)) + theme_classic()
}, res = 75)
trend_dat <- reactive(
mpoxdat %>%
group_by(Date_confirmation) %>%
summarize(ncases = n()) %>%
ungroup() %>%
arrange(Date_confirmation) %>%
mutate(total_cases = cumsum(ncases))
)
output$plot1 <- renderPlot({
ggplot(trend_dat(),
mapping = aes(x = as.Date(Date_confirmation),
y = total_cases)) +
geom_line() +
geom_text(
aes(label =
ifelse(
trend_dat()$total_cases == max(trend_dat()$total_cases),
trend_dat()$total_cases,"")), vjust = -1) +
ylim(0, max(trend_dat()$total_cases) + 500) +
labs(
title = "Trend line",
subtitle = "Algorithm Basics Infographics",
caption = paste("Data source: https://github.com/globaldothealth/monkeypox",
"",
paste("Period:",
min(as.Date(trend_dat()$Date_confirmation)), "to",
max(as.Date(trend_dat()$Date_confirmation))),
sep="\n"),
x = "Country/Region",
y = "Number of Confirmed Cases"
) + theme_bw()
}, res = 75)
wmap1 <- reactive(
mutate(wmap,
colorfill = ifelse(region %in%
mpoxdat1[1:input$topx, ]$Country,
"red",
"white"))
)
output$plot2 <- renderPlot({
ggplot(wmap1(),
aes(long, lat, fill = colorfill, group = group)) +
geom_polygon(colour = "gray") +
labs(
title = "Geomap of countries with active cases",
subtitle = "Algorithm Basics Infographics",
caption = "Data source: https://github.com/globaldothealth/monkeypox",
x = "Longitude",
y = "Latitude"
) +
scale_fill_identity() + theme_classic()
}, res = 75)
}
shinyApp(ui, server)