@@ -326,10 +326,14 @@ map_ng <- function(region = character(),
326326# ' @import mapdata
327327.getMapData.default <- function (x )
328328{
329+ if (is.factor(x ))
330+ x <- as.character(x )
331+ stopifnot(is.character(x ))
329332 if (identical(x , ' Nigeria' ))
330333 return (" mapdata::worldHires" )
331- if (x %in% .synonymRegions() || is_state(x ))
332- return (.getMapData(states()))
334+ if ((length(x ) == 1L && (x %in% .synonymRegions()))
335+ || all(is_state(x )))
336+ return (.getMapData(states(x )))
333337 .getMapData(lgas(x ))
334338}
335339
@@ -523,6 +527,8 @@ map_ng <- function(region = character(),
523527 df $ ind <- as.integer(df $ cat )
524528 df $ color <- colrange [df $ ind ]
525529 mapregions <- .getUniqueStateNames(map )
530+ if (nrow(df ) < length(mapregions ))
531+ mapregions <- mapregions [mapregions %in% df $ region ]
526532 new.ind <- order(df $ region , mapregions )
527533 ord.df <- df [new.ind , ] # This is why a data frame was made
528534 colors <- .reassignColours(map $ names , ord.df $ region , ord.df $ color , ... )
@@ -667,10 +673,15 @@ map_ng <- function(region = character(),
667673# Reassigns colours to polygons that refer to similar regions i.e. duplicated
668674# polygon, ensuring that when the choropleth is drawn, the colours are
669675# properly applied to the respective regions and not recycled.
676+ # ' @importFrom grDevices colours
670677.reassignColours <-
671678 function (names , all.regions , in .colours , excl.region = NULL , excl.col = NULL )
672679{
673- stopifnot(is.character(names ), all(is_state(all.regions )), .isHexColor(in .colours ))
680+ stopifnot({
681+ is.character(names )
682+ all(is_state(all.regions ))
683+ .isHexColor(in .colours )
684+ })
674685 out.colours <- new.names <- rep(NA , length(names ))
675686 for (i in seq_along(all.regions )) {
676687 regx <- .regexDuplicatedPolygons(all.regions [i ])
@@ -683,8 +694,15 @@ map_ng <- function(region = character(),
683694 # # the choropleth and should be given an 'off-colour'
684695 if (! is.null(excl.region )) {
685696 off.color <- " grey"
686- if (! is.null(excl.col ))
697+ if (! is.null(excl.col )) {
698+ if (length(excl.col ) > 1L )
699+ stop(" Non-null 'exclude.fill' must be of length 1L" )
700+ if (! is.character(excl.col ))
701+ stop(" 'exclude.fill' must be a string" )
702+ if (! excl.col %in% colours())
703+ stop(" 'exclude.fill' must be a valid colour" )
687704 off.color <- excl.col
705+ }
688706 excluded <- match(excl.region , new.names )
689707 out.colours [excluded ] <- off.color
690708 }
0 commit comments