The slot for “plotOrder” comes up as 1 instead of a vector with length specific to my data The 2019 Stack Overflow Developer Survey Results Are InSubset a SpatialPolygonsDataFrame by ID in R?Convert a spatial polygon object to data frame using RSpatial weight matrix with boundary effects in R?Dissolving/Unifying Ill Behaved/Irregular Polygons in RData frame to SpatialPolygonsDataFrame with multiple polygons“Hole” argument ignored in call to Polygon functionUnique SpatialPolygons object with multiple polygons slots in RBuilding multiple extents as polygons from lat/long list values in RGroup and aggregate SpatialPolygonsDataFrame by column in RGroup and union polygons that share a border in R

Why doesn't shell automatically fix "useless use of cat"?

Falsification in Math vs Science

Flight paths in orbit around Ceres?

Why does the nucleus not repel itself?

Match Roman Numerals

Using xargs with pdftk

What is the motivation for a law requiring 2 parties to consent for recording a conversation

Cooking pasta in a water boiler

Can we generate random numbers using irrational numbers like π and e?

What is the most efficient way to store a numeric range?

Is it correct to say the Neural Networks are an alternative way of performing Maximum Likelihood Estimation? if not, why?

Geography at the pixel level

Worn-tile Scrabble

I am an eight letter word. What am I?

Relationship between Gromov-Witten and Taubes' Gromov invariant

How can I add encounters in the Lost Mine of Phandelver campaign without giving PCs too much XP?

Did any laptop computers have a built-in 5 1/4 inch floppy drive?

Why was M87 targeted for the Event Horizon Telescope instead of Sagittarius A*?

Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?

A word that means fill it to the required quantity

Why doesn't UInt have a toDouble()?

Is an up-to-date browser secure on an out-of-date OS?

How do you keep chess fun when your opponent constantly defeats?

Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?



The slot for “plotOrder” comes up as 1 instead of a vector with length specific to my data



The 2019 Stack Overflow Developer Survey Results Are InSubset a SpatialPolygonsDataFrame by ID in R?Convert a spatial polygon object to data frame using RSpatial weight matrix with boundary effects in R?Dissolving/Unifying Ill Behaved/Irregular Polygons in RData frame to SpatialPolygonsDataFrame with multiple polygons“Hole” argument ignored in call to Polygon functionUnique SpatialPolygons object with multiple polygons slots in RBuilding multiple extents as polygons from lat/long list values in RGroup and aggregate SpatialPolygonsDataFrame by column in RGroup and union polygons that share a border in R



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















My goal is to find neighbors from my SpatialPolygons object using the poly2nb() command from the sp package in R.



This is my code thus far:



 p <- s_gis %>%
select(long, lat) %>%
Polygon()
ps <- Polygons(list(p), 1000)
sps <- SpatialPolygons(list(ps))


where s_gis is my dataset. I'm otherwise able to make a successful SpatialPolygons object except for the fact that the slot for plotOrder reads 1, instead of 636353 like it is in my dataset.



Running the poly2nb() commands returns an error Error in sp$mbxv[i]:(n * 2) : argument of length 0 which I'm assuming is coming from the fact that it's finding 0 neighbors given that I only have a plotOrder of 1.



How do I modify the plotOrder?



In addition, regarding my error message from the poly2nb() command, if the problem runs deeper, can someone shed some insight as to why?



I have also tried ps@plotOrder <- s_gis$order to no avail.



EDIT:



#get lat, long, and groupid
s_gis_latlon <- s_gis %>%
select(long,lat, group)

#group lists by group id
p_groups <- split(s_gis_latlon, s_gis_latlon$group)

#delete group id so that we can have 2-column matrix for Polygon
p_groups1 <- lapply(p_groups, function(x) x[,3] <- NULL; x )

# turn each element of list into a polygon
p_groups1 <- lapply(names(p_groups1),
function(x) b <- Polygon(p_groups1[[x]])
b
)

#turn list of polygons into Polygons
ps <- Polygons(p_groups1,1)

data <- s_gis %>%
group_by(group) %>%
summarize(district_wealthrange = mean(wealthrange))

#create SpatialPolygons object
sps <- SpatialPolygons(ps@Polygons)


I'm getting the error Error in SpatialPolygons(ps@Polygons) :
no slot of name "Polygons" for this object of class "Polygon"










share|improve this question









New contributor




Lathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • What's s_gis? Can you show us its summary() and maybe its head()? What does sps end up as? Is it one polygon or many? How are you running poly2nb to get that error? What are you running it on? On sps? Do you care about the plot order or working out the neighbourhood?

    – Spacedman
    Apr 5 at 23:37












  • s_gis is one of the datasets I'm using. The summary is quite large; however, I did select out long and lat which results in a tibble with dimensions 661228 x 2. sps ends up Slot "plotOrder": [1] 1 Slot "labpt": [1] 76.83899 29.49845 Slot "ID": [1] "1000" Slot "area": [1] 196.6975 Slot "coords": # I removed these to save char. space Slot "plotOrder": [1] 1 Slot "bbox": min max x 68.186249 97.41529 y 6.755953 37.07827 Slot "proj4string": CRS arguments: +proj=longlat +datum=WGS84

    – Lathan
    Apr 5 at 23:46












  • I'm runnning poly2nb(sps, queen = FALSE) and I care more about working out the neighborhood. Thanks so much for your quick response!

    – Lathan
    Apr 5 at 23:49

















-1















My goal is to find neighbors from my SpatialPolygons object using the poly2nb() command from the sp package in R.



This is my code thus far:



 p <- s_gis %>%
select(long, lat) %>%
Polygon()
ps <- Polygons(list(p), 1000)
sps <- SpatialPolygons(list(ps))


where s_gis is my dataset. I'm otherwise able to make a successful SpatialPolygons object except for the fact that the slot for plotOrder reads 1, instead of 636353 like it is in my dataset.



Running the poly2nb() commands returns an error Error in sp$mbxv[i]:(n * 2) : argument of length 0 which I'm assuming is coming from the fact that it's finding 0 neighbors given that I only have a plotOrder of 1.



How do I modify the plotOrder?



In addition, regarding my error message from the poly2nb() command, if the problem runs deeper, can someone shed some insight as to why?



I have also tried ps@plotOrder <- s_gis$order to no avail.



EDIT:



#get lat, long, and groupid
s_gis_latlon <- s_gis %>%
select(long,lat, group)

#group lists by group id
p_groups <- split(s_gis_latlon, s_gis_latlon$group)

#delete group id so that we can have 2-column matrix for Polygon
p_groups1 <- lapply(p_groups, function(x) x[,3] <- NULL; x )

# turn each element of list into a polygon
p_groups1 <- lapply(names(p_groups1),
function(x) b <- Polygon(p_groups1[[x]])
b
)

#turn list of polygons into Polygons
ps <- Polygons(p_groups1,1)

data <- s_gis %>%
group_by(group) %>%
summarize(district_wealthrange = mean(wealthrange))

#create SpatialPolygons object
sps <- SpatialPolygons(ps@Polygons)


I'm getting the error Error in SpatialPolygons(ps@Polygons) :
no slot of name "Polygons" for this object of class "Polygon"










share|improve this question









New contributor




Lathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • What's s_gis? Can you show us its summary() and maybe its head()? What does sps end up as? Is it one polygon or many? How are you running poly2nb to get that error? What are you running it on? On sps? Do you care about the plot order or working out the neighbourhood?

    – Spacedman
    Apr 5 at 23:37












  • s_gis is one of the datasets I'm using. The summary is quite large; however, I did select out long and lat which results in a tibble with dimensions 661228 x 2. sps ends up Slot "plotOrder": [1] 1 Slot "labpt": [1] 76.83899 29.49845 Slot "ID": [1] "1000" Slot "area": [1] 196.6975 Slot "coords": # I removed these to save char. space Slot "plotOrder": [1] 1 Slot "bbox": min max x 68.186249 97.41529 y 6.755953 37.07827 Slot "proj4string": CRS arguments: +proj=longlat +datum=WGS84

    – Lathan
    Apr 5 at 23:46












  • I'm runnning poly2nb(sps, queen = FALSE) and I care more about working out the neighborhood. Thanks so much for your quick response!

    – Lathan
    Apr 5 at 23:49













-1












-1








-1








My goal is to find neighbors from my SpatialPolygons object using the poly2nb() command from the sp package in R.



This is my code thus far:



 p <- s_gis %>%
select(long, lat) %>%
Polygon()
ps <- Polygons(list(p), 1000)
sps <- SpatialPolygons(list(ps))


where s_gis is my dataset. I'm otherwise able to make a successful SpatialPolygons object except for the fact that the slot for plotOrder reads 1, instead of 636353 like it is in my dataset.



Running the poly2nb() commands returns an error Error in sp$mbxv[i]:(n * 2) : argument of length 0 which I'm assuming is coming from the fact that it's finding 0 neighbors given that I only have a plotOrder of 1.



How do I modify the plotOrder?



In addition, regarding my error message from the poly2nb() command, if the problem runs deeper, can someone shed some insight as to why?



I have also tried ps@plotOrder <- s_gis$order to no avail.



EDIT:



#get lat, long, and groupid
s_gis_latlon <- s_gis %>%
select(long,lat, group)

#group lists by group id
p_groups <- split(s_gis_latlon, s_gis_latlon$group)

#delete group id so that we can have 2-column matrix for Polygon
p_groups1 <- lapply(p_groups, function(x) x[,3] <- NULL; x )

# turn each element of list into a polygon
p_groups1 <- lapply(names(p_groups1),
function(x) b <- Polygon(p_groups1[[x]])
b
)

#turn list of polygons into Polygons
ps <- Polygons(p_groups1,1)

data <- s_gis %>%
group_by(group) %>%
summarize(district_wealthrange = mean(wealthrange))

#create SpatialPolygons object
sps <- SpatialPolygons(ps@Polygons)


I'm getting the error Error in SpatialPolygons(ps@Polygons) :
no slot of name "Polygons" for this object of class "Polygon"










share|improve this question









New contributor




Lathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












My goal is to find neighbors from my SpatialPolygons object using the poly2nb() command from the sp package in R.



This is my code thus far:



 p <- s_gis %>%
select(long, lat) %>%
Polygon()
ps <- Polygons(list(p), 1000)
sps <- SpatialPolygons(list(ps))


where s_gis is my dataset. I'm otherwise able to make a successful SpatialPolygons object except for the fact that the slot for plotOrder reads 1, instead of 636353 like it is in my dataset.



Running the poly2nb() commands returns an error Error in sp$mbxv[i]:(n * 2) : argument of length 0 which I'm assuming is coming from the fact that it's finding 0 neighbors given that I only have a plotOrder of 1.



How do I modify the plotOrder?



In addition, regarding my error message from the poly2nb() command, if the problem runs deeper, can someone shed some insight as to why?



I have also tried ps@plotOrder <- s_gis$order to no avail.



EDIT:



#get lat, long, and groupid
s_gis_latlon <- s_gis %>%
select(long,lat, group)

#group lists by group id
p_groups <- split(s_gis_latlon, s_gis_latlon$group)

#delete group id so that we can have 2-column matrix for Polygon
p_groups1 <- lapply(p_groups, function(x) x[,3] <- NULL; x )

# turn each element of list into a polygon
p_groups1 <- lapply(names(p_groups1),
function(x) b <- Polygon(p_groups1[[x]])
b
)

#turn list of polygons into Polygons
ps <- Polygons(p_groups1,1)

data <- s_gis %>%
group_by(group) %>%
summarize(district_wealthrange = mean(wealthrange))

#create SpatialPolygons object
sps <- SpatialPolygons(ps@Polygons)


I'm getting the error Error in SpatialPolygons(ps@Polygons) :
no slot of name "Polygons" for this object of class "Polygon"







r sp spdep






share|improve this question









New contributor




Lathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Lathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Apr 6 at 18:20







Lathan













New contributor




Lathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Apr 5 at 23:25









LathanLathan

32




32




New contributor




Lathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Lathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Lathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • What's s_gis? Can you show us its summary() and maybe its head()? What does sps end up as? Is it one polygon or many? How are you running poly2nb to get that error? What are you running it on? On sps? Do you care about the plot order or working out the neighbourhood?

    – Spacedman
    Apr 5 at 23:37












  • s_gis is one of the datasets I'm using. The summary is quite large; however, I did select out long and lat which results in a tibble with dimensions 661228 x 2. sps ends up Slot "plotOrder": [1] 1 Slot "labpt": [1] 76.83899 29.49845 Slot "ID": [1] "1000" Slot "area": [1] 196.6975 Slot "coords": # I removed these to save char. space Slot "plotOrder": [1] 1 Slot "bbox": min max x 68.186249 97.41529 y 6.755953 37.07827 Slot "proj4string": CRS arguments: +proj=longlat +datum=WGS84

    – Lathan
    Apr 5 at 23:46












  • I'm runnning poly2nb(sps, queen = FALSE) and I care more about working out the neighborhood. Thanks so much for your quick response!

    – Lathan
    Apr 5 at 23:49

















  • What's s_gis? Can you show us its summary() and maybe its head()? What does sps end up as? Is it one polygon or many? How are you running poly2nb to get that error? What are you running it on? On sps? Do you care about the plot order or working out the neighbourhood?

    – Spacedman
    Apr 5 at 23:37












  • s_gis is one of the datasets I'm using. The summary is quite large; however, I did select out long and lat which results in a tibble with dimensions 661228 x 2. sps ends up Slot "plotOrder": [1] 1 Slot "labpt": [1] 76.83899 29.49845 Slot "ID": [1] "1000" Slot "area": [1] 196.6975 Slot "coords": # I removed these to save char. space Slot "plotOrder": [1] 1 Slot "bbox": min max x 68.186249 97.41529 y 6.755953 37.07827 Slot "proj4string": CRS arguments: +proj=longlat +datum=WGS84

    – Lathan
    Apr 5 at 23:46












  • I'm runnning poly2nb(sps, queen = FALSE) and I care more about working out the neighborhood. Thanks so much for your quick response!

    – Lathan
    Apr 5 at 23:49
















What's s_gis? Can you show us its summary() and maybe its head()? What does sps end up as? Is it one polygon or many? How are you running poly2nb to get that error? What are you running it on? On sps? Do you care about the plot order or working out the neighbourhood?

– Spacedman
Apr 5 at 23:37






What's s_gis? Can you show us its summary() and maybe its head()? What does sps end up as? Is it one polygon or many? How are you running poly2nb to get that error? What are you running it on? On sps? Do you care about the plot order or working out the neighbourhood?

– Spacedman
Apr 5 at 23:37














s_gis is one of the datasets I'm using. The summary is quite large; however, I did select out long and lat which results in a tibble with dimensions 661228 x 2. sps ends up Slot "plotOrder": [1] 1 Slot "labpt": [1] 76.83899 29.49845 Slot "ID": [1] "1000" Slot "area": [1] 196.6975 Slot "coords": # I removed these to save char. space Slot "plotOrder": [1] 1 Slot "bbox": min max x 68.186249 97.41529 y 6.755953 37.07827 Slot "proj4string": CRS arguments: +proj=longlat +datum=WGS84

– Lathan
Apr 5 at 23:46






s_gis is one of the datasets I'm using. The summary is quite large; however, I did select out long and lat which results in a tibble with dimensions 661228 x 2. sps ends up Slot "plotOrder": [1] 1 Slot "labpt": [1] 76.83899 29.49845 Slot "ID": [1] "1000" Slot "area": [1] 196.6975 Slot "coords": # I removed these to save char. space Slot "plotOrder": [1] 1 Slot "bbox": min max x 68.186249 97.41529 y 6.755953 37.07827 Slot "proj4string": CRS arguments: +proj=longlat +datum=WGS84

– Lathan
Apr 5 at 23:46














I'm runnning poly2nb(sps, queen = FALSE) and I care more about working out the neighborhood. Thanks so much for your quick response!

– Lathan
Apr 5 at 23:49





I'm runnning poly2nb(sps, queen = FALSE) and I care more about working out the neighborhood. Thanks so much for your quick response!

– Lathan
Apr 5 at 23:49










1 Answer
1






active

oldest

votes


















0














Now we know enough to reproduce your error message, I'll do that with a data frame of lat-long numbers:



> library(sp)
> s_gis = data.frame(long=runif(5), lat=runif(5))


that should be equivalent to your s_gis with lat-long selected. Continue with your code to make sps:



> p = Polygon(s_gis)
> ps = Polygons(list(p), 1000)
> sps = SpatialPolygons(list(ps))


and now use the spdep package:



> library(spdep)
Loading required package: Matrix
> poly2nb(sps, queen=FALSE)
Error in sp$mbxv[i]:(n * 2) : argument of length 0
>


and there's your error.



poly2nb computes the adjacency matrix between polygons. How many polygons have you got?



> length(sps)
[1] 1
> plot(sps)


enter image description here



One! (although it looks a bit like two but that's because the random lines cross over. This is one ring). No wonder it failed! This data is simply a set of point coordinates in each row - how do you think this data frame could define more than one polygon?






share|improve this answer























  • I've edited my original question. I've tried grouping my coordinates by a group id (which corresponds to each polygon). However, I'm getting a strange lists within a list issue when I make my SpatialPolygon object. The correct plot order is in my sps object; however, it's nested within a list which I can't seem to index. Thus, poly2nb() is still returning the same error message since it's not seeing the plot order and consequently not seeing the correct list of multiple polygon objects that I have.

    – Lathan
    Apr 6 at 18:24











  • You've completely changed the question now. I answered your question about the error you were getting from poly2nb (which didn't even relate to the title about the plot order, but never mind) and now you've added a load of stuff that gives a different error, you've still not shown us some sample data to make a reproducible answer, and I suspect you've left out some important packages necessary to make your code run. I would revert your edits, mark my answer as an answer, and create a new question with your new code, some sample data, and your new error message.

    – Spacedman
    Apr 7 at 11:03











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Lathan is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317953%2fthe-slot-for-plotorder-comes-up-as-1-instead-of-a-vector-with-length-specific%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Now we know enough to reproduce your error message, I'll do that with a data frame of lat-long numbers:



> library(sp)
> s_gis = data.frame(long=runif(5), lat=runif(5))


that should be equivalent to your s_gis with lat-long selected. Continue with your code to make sps:



> p = Polygon(s_gis)
> ps = Polygons(list(p), 1000)
> sps = SpatialPolygons(list(ps))


and now use the spdep package:



> library(spdep)
Loading required package: Matrix
> poly2nb(sps, queen=FALSE)
Error in sp$mbxv[i]:(n * 2) : argument of length 0
>


and there's your error.



poly2nb computes the adjacency matrix between polygons. How many polygons have you got?



> length(sps)
[1] 1
> plot(sps)


enter image description here



One! (although it looks a bit like two but that's because the random lines cross over. This is one ring). No wonder it failed! This data is simply a set of point coordinates in each row - how do you think this data frame could define more than one polygon?






share|improve this answer























  • I've edited my original question. I've tried grouping my coordinates by a group id (which corresponds to each polygon). However, I'm getting a strange lists within a list issue when I make my SpatialPolygon object. The correct plot order is in my sps object; however, it's nested within a list which I can't seem to index. Thus, poly2nb() is still returning the same error message since it's not seeing the plot order and consequently not seeing the correct list of multiple polygon objects that I have.

    – Lathan
    Apr 6 at 18:24











  • You've completely changed the question now. I answered your question about the error you were getting from poly2nb (which didn't even relate to the title about the plot order, but never mind) and now you've added a load of stuff that gives a different error, you've still not shown us some sample data to make a reproducible answer, and I suspect you've left out some important packages necessary to make your code run. I would revert your edits, mark my answer as an answer, and create a new question with your new code, some sample data, and your new error message.

    – Spacedman
    Apr 7 at 11:03















0














Now we know enough to reproduce your error message, I'll do that with a data frame of lat-long numbers:



> library(sp)
> s_gis = data.frame(long=runif(5), lat=runif(5))


that should be equivalent to your s_gis with lat-long selected. Continue with your code to make sps:



> p = Polygon(s_gis)
> ps = Polygons(list(p), 1000)
> sps = SpatialPolygons(list(ps))


and now use the spdep package:



> library(spdep)
Loading required package: Matrix
> poly2nb(sps, queen=FALSE)
Error in sp$mbxv[i]:(n * 2) : argument of length 0
>


and there's your error.



poly2nb computes the adjacency matrix between polygons. How many polygons have you got?



> length(sps)
[1] 1
> plot(sps)


enter image description here



One! (although it looks a bit like two but that's because the random lines cross over. This is one ring). No wonder it failed! This data is simply a set of point coordinates in each row - how do you think this data frame could define more than one polygon?






share|improve this answer























  • I've edited my original question. I've tried grouping my coordinates by a group id (which corresponds to each polygon). However, I'm getting a strange lists within a list issue when I make my SpatialPolygon object. The correct plot order is in my sps object; however, it's nested within a list which I can't seem to index. Thus, poly2nb() is still returning the same error message since it's not seeing the plot order and consequently not seeing the correct list of multiple polygon objects that I have.

    – Lathan
    Apr 6 at 18:24











  • You've completely changed the question now. I answered your question about the error you were getting from poly2nb (which didn't even relate to the title about the plot order, but never mind) and now you've added a load of stuff that gives a different error, you've still not shown us some sample data to make a reproducible answer, and I suspect you've left out some important packages necessary to make your code run. I would revert your edits, mark my answer as an answer, and create a new question with your new code, some sample data, and your new error message.

    – Spacedman
    Apr 7 at 11:03













0












0








0







Now we know enough to reproduce your error message, I'll do that with a data frame of lat-long numbers:



> library(sp)
> s_gis = data.frame(long=runif(5), lat=runif(5))


that should be equivalent to your s_gis with lat-long selected. Continue with your code to make sps:



> p = Polygon(s_gis)
> ps = Polygons(list(p), 1000)
> sps = SpatialPolygons(list(ps))


and now use the spdep package:



> library(spdep)
Loading required package: Matrix
> poly2nb(sps, queen=FALSE)
Error in sp$mbxv[i]:(n * 2) : argument of length 0
>


and there's your error.



poly2nb computes the adjacency matrix between polygons. How many polygons have you got?



> length(sps)
[1] 1
> plot(sps)


enter image description here



One! (although it looks a bit like two but that's because the random lines cross over. This is one ring). No wonder it failed! This data is simply a set of point coordinates in each row - how do you think this data frame could define more than one polygon?






share|improve this answer













Now we know enough to reproduce your error message, I'll do that with a data frame of lat-long numbers:



> library(sp)
> s_gis = data.frame(long=runif(5), lat=runif(5))


that should be equivalent to your s_gis with lat-long selected. Continue with your code to make sps:



> p = Polygon(s_gis)
> ps = Polygons(list(p), 1000)
> sps = SpatialPolygons(list(ps))


and now use the spdep package:



> library(spdep)
Loading required package: Matrix
> poly2nb(sps, queen=FALSE)
Error in sp$mbxv[i]:(n * 2) : argument of length 0
>


and there's your error.



poly2nb computes the adjacency matrix between polygons. How many polygons have you got?



> length(sps)
[1] 1
> plot(sps)


enter image description here



One! (although it looks a bit like two but that's because the random lines cross over. This is one ring). No wonder it failed! This data is simply a set of point coordinates in each row - how do you think this data frame could define more than one polygon?







share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 6 at 8:18









SpacedmanSpacedman

24.9k23551




24.9k23551












  • I've edited my original question. I've tried grouping my coordinates by a group id (which corresponds to each polygon). However, I'm getting a strange lists within a list issue when I make my SpatialPolygon object. The correct plot order is in my sps object; however, it's nested within a list which I can't seem to index. Thus, poly2nb() is still returning the same error message since it's not seeing the plot order and consequently not seeing the correct list of multiple polygon objects that I have.

    – Lathan
    Apr 6 at 18:24











  • You've completely changed the question now. I answered your question about the error you were getting from poly2nb (which didn't even relate to the title about the plot order, but never mind) and now you've added a load of stuff that gives a different error, you've still not shown us some sample data to make a reproducible answer, and I suspect you've left out some important packages necessary to make your code run. I would revert your edits, mark my answer as an answer, and create a new question with your new code, some sample data, and your new error message.

    – Spacedman
    Apr 7 at 11:03

















  • I've edited my original question. I've tried grouping my coordinates by a group id (which corresponds to each polygon). However, I'm getting a strange lists within a list issue when I make my SpatialPolygon object. The correct plot order is in my sps object; however, it's nested within a list which I can't seem to index. Thus, poly2nb() is still returning the same error message since it's not seeing the plot order and consequently not seeing the correct list of multiple polygon objects that I have.

    – Lathan
    Apr 6 at 18:24











  • You've completely changed the question now. I answered your question about the error you were getting from poly2nb (which didn't even relate to the title about the plot order, but never mind) and now you've added a load of stuff that gives a different error, you've still not shown us some sample data to make a reproducible answer, and I suspect you've left out some important packages necessary to make your code run. I would revert your edits, mark my answer as an answer, and create a new question with your new code, some sample data, and your new error message.

    – Spacedman
    Apr 7 at 11:03
















I've edited my original question. I've tried grouping my coordinates by a group id (which corresponds to each polygon). However, I'm getting a strange lists within a list issue when I make my SpatialPolygon object. The correct plot order is in my sps object; however, it's nested within a list which I can't seem to index. Thus, poly2nb() is still returning the same error message since it's not seeing the plot order and consequently not seeing the correct list of multiple polygon objects that I have.

– Lathan
Apr 6 at 18:24





I've edited my original question. I've tried grouping my coordinates by a group id (which corresponds to each polygon). However, I'm getting a strange lists within a list issue when I make my SpatialPolygon object. The correct plot order is in my sps object; however, it's nested within a list which I can't seem to index. Thus, poly2nb() is still returning the same error message since it's not seeing the plot order and consequently not seeing the correct list of multiple polygon objects that I have.

– Lathan
Apr 6 at 18:24













You've completely changed the question now. I answered your question about the error you were getting from poly2nb (which didn't even relate to the title about the plot order, but never mind) and now you've added a load of stuff that gives a different error, you've still not shown us some sample data to make a reproducible answer, and I suspect you've left out some important packages necessary to make your code run. I would revert your edits, mark my answer as an answer, and create a new question with your new code, some sample data, and your new error message.

– Spacedman
Apr 7 at 11:03





You've completely changed the question now. I answered your question about the error you were getting from poly2nb (which didn't even relate to the title about the plot order, but never mind) and now you've added a load of stuff that gives a different error, you've still not shown us some sample data to make a reproducible answer, and I suspect you've left out some important packages necessary to make your code run. I would revert your edits, mark my answer as an answer, and create a new question with your new code, some sample data, and your new error message.

– Spacedman
Apr 7 at 11:03










Lathan is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















Lathan is a new contributor. Be nice, and check out our Code of Conduct.












Lathan is a new contributor. Be nice, and check out our Code of Conduct.











Lathan is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317953%2fthe-slot-for-plotorder-comes-up-as-1-instead-of-a-vector-with-length-specific%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

រឿង រ៉ូមេអូ និង ហ្ស៊ុយលីយេ សង្ខេបរឿង តួអង្គ បញ្ជីណែនាំ

Crop image to path created in TikZ? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Crop an inserted image?TikZ pictures does not appear in posterImage behind and beyond crop marks?Tikz picture as large as possible on A4 PageTransparency vs image compression dilemmaHow to crop background from image automatically?Image does not cropTikzexternal capturing crop marks when externalizing pgfplots?How to include image path that contains a dollar signCrop image with left size given

Romeo and Juliet ContentsCharactersSynopsisSourcesDate and textThemes and motifsCriticism and interpretationLegacyScene by sceneSee alsoNotes and referencesSourcesExternal linksNavigation menu"Consumer Price Index (estimate) 1800–"10.2307/28710160037-3222287101610.1093/res/II.5.31910.2307/45967845967810.2307/2869925286992510.1525/jams.1982.35.3.03a00050"Dada Masilo: South African dancer who breaks the rules"10.1093/res/os-XV.57.1610.2307/28680942868094"Sweet Sorrow: Mann-Korman's Romeo and Juliet Closes Sept. 5 at MN's Ordway"the original10.2307/45957745957710.1017/CCOL0521570476.009"Ram Leela box office collections hit massive Rs 100 crore, pulverises prediction"Archived"Broadway Revival of Romeo and Juliet, Starring Orlando Bloom and Condola Rashad, Will Close Dec. 8"Archived10.1075/jhp.7.1.04hon"Wherefore art thou, Romeo? To make us laugh at Navy Pier"the original10.1093/gmo/9781561592630.article.O006772"Ram-leela Review Roundup: Critics Hail Film as Best Adaptation of Romeo and Juliet"Archived10.2307/31946310047-77293194631"Romeo and Juliet get Twitter treatment""Juliet's Nurse by Lois Leveen""Romeo and Juliet: Orlando Bloom's Broadway Debut Released in Theaters for Valentine's Day"Archived"Romeo and Juliet Has No Balcony"10.1093/gmo/9781561592630.article.O00778110.2307/2867423286742310.1076/enst.82.2.115.959510.1080/00138380601042675"A plague o' both your houses: error in GCSE exam paper forces apology""Juliet of the Five O'Clock Shadow, and Other Wonders"10.2307/33912430027-4321339124310.2307/28487440038-7134284874410.2307/29123140149-661129123144728341M"Weekender Guide: Shakespeare on The Drive""balcony"UK public library membership"romeo"UK public library membership10.1017/CCOL9780521844291"Post-Zionist Critique on Israel and the Palestinians Part III: Popular Culture"10.2307/25379071533-86140377-919X2537907"Capulets and Montagues: UK exam board admit mixing names up in Romeo and Juliet paper"Istoria Novellamente Ritrovata di Due Nobili Amanti2027/mdp.390150822329610820-750X"GCSE exam error: Board accidentally rewrites Shakespeare"10.2307/29176390149-66112917639"Exam board apologises after error in English GCSE paper which confused characters in Shakespeare's Romeo and Juliet""From Mariotto and Ganozza to Romeo and Guilietta: Metamorphoses of a Renaissance Tale"10.2307/37323537323510.2307/2867455286745510.2307/28678912867891"10 Questions for Taylor Swift"10.2307/28680922868092"Haymarket Theatre""The Zeffirelli Way: Revealing Talk by Florentine Director""Michael Smuin: 1938-2007 / Prolific dance director had showy career"The Life and Art of Edwin BoothRomeo and JulietRomeo and JulietRomeo and JulietRomeo and JulietEasy Read Romeo and JulietRomeo and Julieteeecb12003684p(data)4099369-3n8211610759dbe00d-a9e2-41a3-b2c1-977dd692899302814385X313670221313670221