r - Plotting a subset of neighbours from spdep package -


i'm interested in creating single plot polygon , neighbours created via poly2nb function available through spdep package.

preparation

i'm creating nb object in following manner:

# download read state shapefiles tmp_shps <- tempfile(fileext = ".zip") tmp_dir <- tempdir() download.file(     "http://www2.census.gov/geo/tiger/genz2014/shp/cb_2014_us_state_20m.zip",     tmp_shps ) unzip(tmp_shps, exdir = tmp_dir)  # import shpspoly <- maptools::readshapepoly(verbose = true,                                     fn =                                         file.path(tmp_dir, "cb_2014_us_state_20m")) # nbs usanbs <- spdep::poly2nb(pl = shpspoly,                          queen = true) 

subsetting

if try subset keeping first polygon following error:

# nbs usanbs <- spdep::poly2nb(pl = shpspoly,                          queen = true) coords <- sp::coordinates(usanbs)  sbstusanbs <- spdep::subset.nb(x = usanbs, coords = coords,                                 subset = (1:length(usanbs) %in% 1)) plot(sbstusanbs, coords[(-2:length(usanbs)),]) 

error:

error in (function (classes, fdef, mtable)  :    unable find inherited method function ‘coordinates’ signature ‘"nb"’ 

i'm interested in plotting one polygon and neighbours.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -