Description Usage Arguments Details Value Examples
Draws a choropleth map
1 2 | choromap(df, map, fixedBreaks, col = heat.colors(6), col_na = "grey",
...)
|
df |
a data frame containing at two colums, one of class "character" and one of class "numeric". |
map |
an object of class "SpatialPolygonsDataFrame" containing at least
one column containing the same observations and name as the character column
of the dataframe |
fixedBreaks |
a vector of value used to specife the class intervals. |
col |
a vector of colors to use for the map (by default,
|
col_na |
the color with which to represent the missing values
(by default |
... |
arguments to be passed to plot |
It's important that the parameters df
and map
has one
columns in commun, to be able to link them.
A numeric vector containing the breaks value and the attributes
colors
corresponding to the color associated with the breaks value,
returned invisibly.
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 | library(gdpm)
library(magrittr)
library(gadmVN)
# dengue data
dengue <- getid(dengue, from = 1990, to = 2010)
# geographic data
map <- gadmVN::gadm(date = 1990, merge_hanoi = TRUE) %>% sf::as_Spatial()
# A choroplet map of the dengue data:
# The first step is to select only the month and the year that we want to
# represent, here the incidence value of dengue in September 1993. We keep
# only the 'province' and 'incidence_dengue' column as the 'choromap'
# function accept only dataframe of the two columns in entry.
# The second step is to print the map.
# The last step is to print a legend, here we use legend2 of the 'poseid'
# package but other function can be used.
library(dplyr)
dengue_0993 <- filter(dengue, year == 1993, month == "September")
dengue_0993 <- select(dengue_0993, province, contains("incidence"))
a <- choromap(dengue_0993, map, fixedBreaks = c(0,10,50,100,500,1000,2000))
# return invisibly the information for the legend
legend2(legend = a, col = attr(a, "colors"), col_na = "grey")
# You can also use the '%>%' operator:
dengue_0993 %>%
choromap(map, fixedBreaks = c(0,10,50,100,500,1000,2000)) %>%
legend2(legend = ., col = attr(., "colors"), col_na = "grey")
# Using some other color palettes, for examples the ones from the
# RColorBrewer package or the one in the color Palettes of R, be careful
# to have a color vector of length n-1 compare to the lenght of fixedBreakss:
library(RColorBrewer)
# to see the available color palettes:
display.brewer.all()
dengue_0993 %>%
choromap(map, fixedBreaks = c(0,10,50,100,500,1000,2000),
col = brewer.pal(6, "YlOrRd")) %>%
legend2(legend = ., col = attr(., "colors"), col_na = "grey")
# changing the color of the missing values:
dengue_0993 %>%
choromap(map, fixedBreaks = c(0,10,50,100,500,1000,2000),
col = brewer.pal(6, "YlOrRd"), col_na = "blue") %>%
legend2(legend = ., col = attr(., "colors"), col_na = "blue")
# drawing a map without border:
dengue_0993 %>%
choromap(map, fixedBreaks = c(0,10,50,100,500,1000,2000),
col = brewer.pal(6, "YlOrRd"), col_na = "blue",
border = NA) %>%
legend2(legend = ., col = attr(., "colors"), col_na = "blue")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.