I have a hard time to figure out why I can't map the right country on the map. I have gone through all of my codes, I still don't understand why is not working right.
If you see any problems, please let me know. I appreciate.
This is dataset
Country Total Code
1 China 34620 CHN
2 Japan 89 JPN
3 Singapore 40 SGP
4 Thailand 32 THA
5 Hong Kong 26 HKG
6 S. Korea 24 KOR
7 Taiwan 17 TWN
8 Malaysia 16 MYS
9 Australia 15 AUS
10 Germany 14 DEU
11 Vietnam 13 VNM
12 USA 12 USA
13 France 11 FRA
14 Macao 10 MAC
15 U.A.E. 7 ARE
16 Canada 7 CAN
17 Philippines 3 PHL
18 India 3 IND
19 Italy 3 ITA
20 U.K. 3 GBR
21 Russia 2 RUS
22 Finland 1 FIN
23 Sri Lanka 1 LKA
24 Sweden 1 SWE
25 Nepal 1 NPL
26 Cambodia 1 KHM
27 Spain 1 ESP
28 Belgium 1 BEL
library(leaflet)
library(maps)
library(maptools)
case <- read.csv("Cases_02072020_v1.csv",stringsAsFactors = FALSE)
Country = map("world", fill = TRUE, plot = FALSE, regions=iso.expand(case$Code,regex = TRUE))
IDs <- sapply(strsplit(Country$names, ":"), function(x) x[1])
Country <- map2SpatialPolygons(Country,
IDs=IDs,
proj4string=CRS("+proj=longlat +datum=WGS84"))
pal <- colorNumeric(
palette = "Blues",
domain = as.numeric(case$Total))
case$labels <- sprintf(
"<strong>Country:%s</strong><br/>Total:%g",
case$Country, case$Total)%>% lapply(htmltools::HTML)
leaflet(Country) %>% addTiles() %>%
addPolygons(fillOpacity = 0.6, smoothFactor = 0.5, stroke = TRUE, weight = 1,
color = pal(as.numeric(case$Total)),
label = case$labels)

leafletbut are you not plotting the whole world with your callCountry = map("world"...andleaflet(Country)...- MarBlo