Description Usage Arguments Value Examples
Makes a spatio-temporal heatmap of a disease
1 2 |
df |
A data frame. Should contains three variables: one of class "character", one of class "Date", and one colums of 'numeric' class containing the value to represent. |
f |
a transforming function. By default the identity function. |
col |
a vector of colors to use for the heatmap. |
col_na |
the color with which to represent the missing values. |
x |
a numeric values between 0 and 1. In proportion of the figure's range, this number express the location of the right end of the heatmap, and can be used for the beginning of a legend point |
show_legend |
logical value saying whether the names of the
provinces and the value breaks should be returned as an output of the
function call or not. By default |
map |
object of class Spatial (see |
xm |
a numeric value between 0 and 1. In proportion of the
figure's range, this number express the location of the right end of the
|
A numeric vector corresponding to the value of the legend, returned
invisibly.
If show_legend = TRUE, return a list
containing a numeric vector called legend corresponding to the value
of the legend, and a character vector called province containing the
name of the province in the order of the figure.
A map of the province can be print on the left of the heatmap with
the parameters map and xm. The map need to have the same
spatial definitions as the data frame (df) contains in the first
column of the slots data, so that each line of the heatmap can be
link with the map.
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 | # Packages and parameters
library(gdpm)
library(dplyr)
library(magrittr)
par(xpd = TRUE)
# A heatmap of the ILI data:
ili <- getid(ili, from = 2004) %>%
dplyr::mutate(time = as.Date(
paste0(year, "-", as.numeric(month), "-", 15))) %>%
dplyr::select(province, time, contains("incidence")) %>%
dplyr::arrange(time)
sthm(ili)
# With a legend by using legend2 function:
col <- rev(heat.colors(10))
a <- sthm(ili, col = col)
legend2(0.925, 1, legend = a, col = col, postext = "right",
h = 1/(length(a)-1), w = 0.04, tl = 0.01, s = 0.005)
# A large number of color can be used to
col <- rev(heat.colors(100))
a <- sthm(ili, col = col, col_na = "blue")
legend2(0.925, 1, legend = a, col = col, postext = "right", col_na = "blue",
h = 1/(length(a)-1), w = 0.04, tl = 0.01, s = 0.005)
col <- rev(heat.colors(400))
a <- sthm(ili, col = col, col_na = "blue")
legend2(0.925, 1, legend = a, col = col, postext = "right", col_na = "blue",
h = 1/(length(a)-1), w = 0.04, tl = 0.01, s = 0.005)
# with some data transformations in order to reflect better the contrasts:
a <- sthm(ili, f = sqrt, col = col)
legend2(0.925, 1, legend = a, col = col, postext = "right",
h = 1/(length(a)-1), w = 0.035, tl = 0.01, s = 0.005, cex = 0.8)
a <- sthm(ili, f = function(x) x^.3, col = col)
legend2(0.925, 1, legend = a, col = col, postext = "right",
h = 1/(length(a)-1), w = 0.04, tl = 0.01, s = 0.005, cex = 0.8)
# changing the color of the missing values:
dengue <- getid(dengue) %>%
mutate(time = as.Date(paste0(year, "-", as.numeric(month), "-", 15))) %>%
select(province, time, contains("incidence")) %>%
arrange(time)
col <- rev(heat.colors(400))
a <- sthm(dengue, f = sqrt, col = col)
legend2(0.925, 1, legend = a, col = col, postext = "right",
col_na = "grey", h = 1/(length(a) - 1), w = 0.04, tl = 0.01,
s = 0.005)
a <- sthm(dengue, f = sqrt, col = col, col_na = "blue")
legend2(0.925, 1, legend = a, col = col, postext = "right", n_round = 2,
col_na = "blue", h = 1/(length(a) - 1), w = 0.04, tl = 0.01,
s = 0.005)
# to order the provinces by latitude:
library(gadmVN)
map <- gadmVN::gadm("1980-01-01", merge_hanoi = TRUE) %>% sf::as_Spatial()
coord <- sp::coordinates(map) %>% as.data.frame()
coord$province <- unique(map@data[, 1])
coord <- coord[order(coord$V2),]
coord$order <- seq(1, dim(coord)[1], 1)
dengue_order <- left_join(dengue, coord, by = "province") %>%
arrange(order) %>%
select(-order, -V1, -V2)
a <- sthm(dengue_order, f = function(x) x^.3, col = col)
legend2(0.925, 1, legend = a, col = col, postext = "right",
h = 1/(length(a)-1), w = 0.04, tl = 0.01, s = 0.005)
# to print the map of the province in the order of the figure:
a <- sthm(dengue_order, f = function(x) x^.3, col = col, map = map)
legend2(0.925, 1, legend = a, col = col, postext = "right",
h = 1/(length(a)-1), w = 0.04, tl = 0.01, s = 0.005)
# to print the map of the province and the legend in the order of the figure:
a <- sthm(dengue_order, f = function(x) x^.3, col = col, map = map,
show_legend = TRUE)
legend2(0.925, 1, legend = a$legend, col = col, postext = "right",
h = 1/(length(col)), w = 0.04, tl = 0.01, s = 0.005)
a
# list containing the legend vector and the province vector which correspond
# to the name of the province in the order of the figure.
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.