0

I am new to R and am having trouble plotting a SpatialPointsDataFrame, with eventual hopes of creating minimum convex polygons. I've been trying for a few days but can't find anything to fix this problem.

I load my excel data as TXT. File has 3 columns (Latitude, Longitude, ID) and 549 rows of observations. Then I enter the following code:

# Create coordinates variable
coords <- cbind(LAT = as.numeric(as.character(multi$LAT)), LONG = as.numeric(as.character(multi$LONG)))
# Create the SpatialPointsDataFrame
multi_SPDF <- SpatialPointsDataFrame(coords, data = data.frame(multi$ID), proj4string = CRS("+init=epsg:4326"))
#Plot the points
plot(multi_SPDF)

When I enter this, it produces a plot that looks like this:

I made this code from a similar code found at this link: http://www.alex-singleton.com/R-Tutorial-Materials/7-converting-coordinates.pdf

If anyone is able to help me to make this work I would really appreciate it. Hopefully I provided all of the necessary information.

EDIT

In an attempt to provide a reproducible example, I extracted the head of the data to copy into the comment, as follows:

        LAT     LONG ID
1 -41.30853 174.7342  7
2 -41.30481 174.7353  6
3 -41.30681 174.7363  7
4 -41.30660 174.7360 10
5 -41.31400 174.7329 10
6 -41.31059 174.7350  6

When I ran the above code on these 6 rows alone, it produced a plot with points distributed vertically and horizontally (exactly what I wanted!)

Plot of 6 Observations

However, the same code still does not work on my entire data set. So I think the problem may be in my excel file and not my code.

  • please provide a reproducible example – Cyrus Mohammadian Sep 09 '16 at 18:48
  • Thanks Cyrus. I'm not sure how to attach the file in the comments. But if I did, would that be helpful? – Katie Sheridan Sep 09 '16 at 19:09
  • Edit the example into your question. See [here](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for some ideas on how to make or include a reproducible example. – aosmith Sep 09 '16 at 21:07
  • Probably there's something weird in your data that's causing it to be a `factor` in the first place. Do you get a warning about "NAs introduced by coercion" when you convert to numeric? Maybe look at `MULTI[is.na(as.numeric(as.character(multi$LAT)) + as.numeric(as.character(multi$LONG))), ]` – Gregor Thomas Sep 10 '16 at 00:13
  • The other possibility is that the points *are* distributed horizontally and vertically as you desire, but one point is an extreme vertical outlier. Look at `summary(coords[, 1])` to see the range of the latitudes and the max value. – Gregor Thomas Sep 10 '16 at 00:15
  • Thank you Gregor! It ended up being an outlying longitude. Now that I've fixed that number and swapped the LAT/LONG columns, it looks perfect! – Katie Sheridan Sep 10 '16 at 01:41

0 Answers0