Created
September 3, 2013 14:08
-
-
Save stevenworthington/6424457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sp) | |
library(maptools) | |
# get North Carolina shape data | |
NC <- readShapePoly(system.file("shapes/sids.shp", package = "maptools")[1], | |
IDvar = "FIPSNO", proj4string = CRS("+proj=longlat +ellps=clrk66")) | |
# plot polygons | |
plot(NC, border = "blue", axes = TRUE, las = 1) | |
# create random spatial points object | |
set.seed(123) | |
points <- spsample(x = NC, n = 100, type = "random") | |
# promote to SpatialPointsDataFrame | |
points_df <- SpatialPointsDataFrame(points, data = data.frame(point_id = 1:100)) | |
# add points to plot | |
plot(points_df, col = "orange", add = TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment