plot - R: plotting neighbouring countries using maptools -


say plotting countries on world map using maptools, if plot country, there way of plotting countries border country in different colour? using shapefile wrld_simpl comes maptools, plot china:

plot(wrld_simpl[wrld_simpl$name=='china',], col='red', add=t) 

is there way can plot bordering countries china. want able lots of different countries i'd ideally want general solution, not 1 specific china.

how gtouches or gintersects in rgeos?

library(rgeos) library(maptools) wc <- subset(wrld_simpl, name == "china") world <- subset(wrld_simpl, !name == "china") 

create vector store test:

tst <- logical(nrow(world)) 

do test:

for (i in 1:nrow(world)) {     tst[i] <- gtouches(wc, world[i,]) } 

see result:

levels(world$name)[world$name[tst]] [1] "india"  "russia"  plot(wc) plot(world[tst, ], add = true, col = "grey") 

(no further correspondence on world affairs entered into, gintersects seems give better answer).

i strongly advise treat these built-in data sets caution, need hands on reliable data if use such tool non-trivial purpose. geometry , data tricky enough already. :)

for (i in 1:nrow(world)) {      tst[i] <- gintersects(wc, world[i,])  } length(levels(world$name)[world$name[tst]]) [1] 14  plot(world[tst, ], col = "firebrick")  plot(wc, add = true, col = "grey") 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -