#Simulations using the maps package: library(maps) q <- map("county", "ca") #What does object q contain? See the names first: names(q) #We want the range of the longitude and latitude: q$range[1] q$range[2] q$range[3] q$range[4] #Randomly select 200 points from the box defined by the longitude and latitude ranges: xx <- runif(200,q$range[1], q$range[2]) yy <- runif(200,q$range[3], q$range[4]) #Find the state in which each point falls: in.what.state <- map.where(database="state", xx, yy) #Find the points that fall in California: in.this.state <- which(in.what.state=="california") #Create a data frame of the California points: locations <- as.data.frame(cbind(xx,yy)) loc <- locations[in.this.state,] #Plot the points on the map: map("county", "ca") points(loc)