removing antarctica from the map

347 views
Skip to first unread message

shahnveer

unread,
Sep 19, 2017, 5:57:05 AM9/19/17
to rworldmap
hi,
I am using a rworldmap package to draw a map for data I have of different countries, I want to remove Antarctica from it, can anyone help me out here?
datadf=read_excel("country P&R Info.xlsx","country data" )
#mapping excel data with map data
mapfile <- joinCountryData2Map( datadf,joinCode = "ISO3",nameJoinColumn = "ISO Code")
#showing map data with rworldmap!
mapParams<-mapCountryData(mapfile,nameColumnToPlot="status",mapRegion = "world",addLegend=FALSE, catMethod="categorical",colourPalette=c('orangered2','maroon3'), missingCountryCol = "grey40" )
#changing legendText
mapParams$legendText <-c('yes','No')
#add legend
do.call( addMapLegendBoxes, c(mapParams,x='bottom',title="none"))

Wei Zhang

unread,
Sep 19, 2017, 6:29:35 PM9/19/17
to shahnveer, rworldmap
That will do . Shahnveer.

centered.map <- getMap()

n.1 <- length(centered.map@polygons)

### 
for(i in 1:n.1){
n.2 <- length(centered.map@polygons[[i]]@Polygons)
for(j in 1:n.2){
print(cat(paste(i,"@",j),"\n"))
          ## remove Antarctic region
     if(centered.map@polygons[[i]]@ID=="ATA"){
      tmp.coords <- centered.map@polygons[[i]]@Polygons[[j]]@coords
      nr <- nrow(tmp.coords)
      tmp.coords <- matrix(rep(NA,2*nr),ncol=2)
      centered.map@polygons[[i]]@Polygons[[j]]@coords <- tmp.coords
     }
}
}

--
You received this message because you are subscribed to the Google Groups "rworldmap" group.
To post to this group, send email to rwor...@googlegroups.com.
Visit this group at https://groups.google.com/group/rworldmap.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rworldmap/37879de2-3238-40cf-b2f1-f9242f3e4224%40googlegroups.com.

shahnveer

unread,
Sep 20, 2017, 1:20:35 AM9/20/17
to rworldmap

i dont want to sound stupid but why so many loops here, we can trim the map with other method also, but problem is coming while i am joining my data to the available map data, my 'datadf' is matching the 'ISO' codes and printing the information on map, i want to match the 'datadf, with the trimmed map, that is the actual problem.

trmap <-getMap()[-which(getMap()$ADMIN=='Antarctica'),]
Reply all
Reply to author
Forward
0 new messages