I am looking to produce a data set of randomised coordinates points that can easily be generated in R with something like:
Seqlat <- seq(from=-90, to=90, by=.01)
Seqlong <- seq(from=-180, to=180, by=.01)
Latitude <- sample(Seqlat, size=1000, replace=TRUE)
Longitude <- sample(Seqlong, size=1000, replace=TRUE)
VirtualCoordinates <- data.frame(x= Longitude, y = Latitude)
but instead of completely random coordinates, I am looking for all my coordinates to only be over land.
I can visualise and detect which points occur on land with ggplot2:
WorldData <- map_data('world')
Vcoordinates_map <- ggplot() +
geom_map(data = WorldData, map = WorldData,
aes(x = long, y = lat, group = group, map_id=region),
fill = "white", colour = "#7f7f7f", size=0.5) +
coord_equal()+
theme_bw() +
stat_binhex(data=VirtualCoordinates,
bins = 100, colour = "black",
aes(x = Longitude, y = Latitude))
Vcoordinates_map
But I not sure how to set "land" as a condition or an if statement, when generating the data set.
Any ideas on how to achieve this?