-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplots.R
65 lines (44 loc) · 2.08 KB
/
plots.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
library(tidyverse)
library(readr)
library(viridis)
library(scales)
library(highcharter)
library(htmlwidgets)
options(browser = "/usr/bin/firefox")
mapdata <- get_data_from_map(download_map_data("custom/africa"))
african_data <- read_csv("../../african_data.csv")
african_data$Date <- as.Date(as.character(african_data$Date), format = "%Y-%m-%d")
names(african_data)[26] <- "Testing_Policy"
african_data$y <- african_data$CountryName
testing_data <- african_data[, names(african_data) %in% c("Date", "CountryName", "Testing_Policy", "CountryCode")]
testing_data <- testing_data[complete.cases(testing_data), ]
testing_data$CountryName <- factor(testing_data$CountryName,levels=rev(unique(testing_data$CountryName)))
## testing_data <- testing_data[testing_data$Date > "2020-02-14", ]
testing_data <- testing_data[testing_data$CountryName != "France",]
## just get max------------------
just_testing_data_latest <- testing_data %>%
group_by(CountryName) %>%
arrange(Date) %>%
mutate(max_testing_data = max(unique(Date)))
just_testing_data_latest <- just_testing_data_latest[(just_testing_data_latest$Date == just_testing_data_latest$max_testing_data), ]
names(just_testing_data_latest)[2] <- "iso-a3"
## graphic
x <- c("Country", "Date", "Testing Policy")
y <- c("{point.CountryName}" , "{point.Date}", "{point.Testing_Policy}")
tltip <- tooltip_table(x, y)
carmine <- "#960018"
dark_midnight_blue <- "#003366"
white <- "#FFFFFF"
milken <- "#0066CC"
milken_red <- "#ff3333"
## map cases per of pop
testing_policy_map <- hcmap("custom/africa", data = just_testing_data_latest, value = "Testing_Policy",
joinBy = c("iso-a3"), name = "Testing Policy",
borderColor = "#FAFAFA", borderWidth = 0.1) %>%
hc_tooltip(useHTML = TRUE, headerFormat = "", pointFormat = tltip) %>%
hc_legend(align = "center", layout = "horizontal", verticalAlign = "middle", x = -160, y= 120, valueDecimals = 0) %>%
hc_colorAxis(minColor = "#e2e2e2", maxColor = milken_red,
type = "linear")
## testing_policy_map
## Save vis
saveWidget(testing_policy_map, file="testing_policy_map.html")