Description Usage Arguments Details Examples
Draws a scale legend
| 1 2 3 | 
| x | A numeric value for the x coordinate of the top-left part of the legend | 
| y | A numeric value for the y coordinate of the top-left part of the legend | 
| legend | A character or expression vector to appear in the legend. | 
| col | A vector of colors, if there are too few elements to fill the
legend, the elements in  | 
| locate | A boolean, if TRUE, call the function  | 
| pos | A character, by default  | 
| n_round | An integer indicating the number of significant digits to be
used, by default  | 
| col_na | the color with which to represent the missing values
(by default  | 
| size_na | A numeric value expressing the size of the rectangle for the
missing value, expressed in a proportion of the scale legend (between 0 and
1, by default  | 
| postext | A character defining the side of the legend text, by default
 | 
| h | A numeric expressing the height of one rectangle in the legend | 
| w | A numeric expressing the width of the legend | 
| tl | A numeric expressing the length of the tick | 
| s | A numeric parameter expressing the space between the text and the tick | 
| ... | if need to imput more text parameters for the legend | 
The number of rectangle in the scale legend is calculate with the
number of color in the vector col.
 If arguments x,y are not filled, the location may also be
specified by setting the parameter pos to a keyword form the list:
"top-left", "top-right", "bottom-left" or
"bottom-right". This places the legend on the inside of the plot
frame at the giver location. 
 Note that a call to the function locator(1) can be used via
setting the parameter locate to TRUE in place of the x and
y arguments. 
 If the length of the vector legend is higher than 12, the axis
legend will be calculate with the R break algorithm as implemented in pretty.
| 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 | library(gdpm)
library(magrittr)
library(gadmVN)
# dengue data
dengue <- getid(dengue, from = 1992, to = 2010)
# geographic data
map <- gadmVN::gadm(date = 1992, merge_hanoi = TRUE) %>% sf::as_Spatial()
# preparation of the data
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))
# By default, col = heat.colors(6) in choromap function
legend2(97, 22.5 ,a ,col = heat.colors(6))
# By default, the legend is on the top left of the figure if x and y are not
# filled, but the position can be easily change by using the parameters pos:
# top left
a <- choromap(dengue_0993, map, fixedBreaks = c(0,10,50,100,500,1000,2000))
legend2(legend = a, col = heat.colors(6))
# top right
a <- choromap(dengue_0993, map, fixedBreaks = c(0,10,50,100,500,1000,2000))
legend2(legend = a, col = heat.colors(6), pos = "top-right")
# bottom left
a <- choromap(dengue_0993, map, fixedBreaks = c(0,10,50,100,500,1000,2000))
legend2(legend = a, col = heat.colors(6), pos = "bottom-left")
# bottom right
a <- choromap(dengue_0993, map, fixedBreaks = c(0,10,50,100,500,1000,2000))
legend2(legend = a, col = heat.colors(6), pos = "bottom-right")
# By default, the legend text is on the left of the scale, but the
# position can be easily change by using the parameters postext:
a <- choromap(dengue_0993, map, fixedBreaks = c(0,10,50,100,500,1000,2000))
legend2(legend = a, col = heat.colors(6), pos = "bottom-right",
         postext = "right")
# Printing the color of the missing values:
a <- choromap(dengue_0993, map, fixedBreaks = c(0,10,50,100,500,1000,2000))
legend2(legend = a, col = heat.colors(6), col_na = "grey")
# Changing the number of decimal:
a <- choromap(dengue_0993, map,
               fixedBreaks = c(0, 0.5, 5, 50, 150, 1000, 2000))
legend2(legend = a, col = heat.colors(6), col_na = "grey", n_round = 1)
# Changing the text parameters:
a <- choromap(dengue_0993, map,
               fixedBreaks = c(0, 0.5, 5, 50, 150, 1000, 2000))
legend2(legend = a, col = heat.colors(6), col_na = "grey", n_round = 2,
         cex = 0.8)
# Changing the parameters of the scale:
a <- choromap(dengue_0993, map,
               fixedBreaks = c(0, 0.5, 5, 50, 150, 1000, 2000))
legend2(legend = a, col = heat.colors(6), col_na = "grey",
         h = 0.5, w = 0.4, cex = 0.6)
# Using the locator to choose where to print the legend
## Not run: 
choromap(dengue_0993, map)
legend2(legend = a, col = heat.colors(6), locate = TRUE)
## End(Not run)
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.