Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 56 lines (48 sloc) 2.103 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
### this tutorial manly follows this webpage
### https://sites.google.com/site/rodriguezsanchezf/news/usingrasagis

library(dismo)
library(maps)
 
### get GBIF data with function gbif
spec <- c("campanula", "scheuchzeri")
distr <- gbif(spec[1], spec[2], removeZeros = TRUE)
summary(distr) # removeZeros doesn't seem to work..
distr <- distr[distr$lat!=0 | distr$lon!=0,]
### set spatial coordinates
coordinates(distr) <- c("lon", "lat")

### Subsetting
table(distr@data$country) # see occurrences by country
distr.at <- subset(distr, distr$country=="AT") # select only distr in Austria
summary(distr.at)

### check on a simple plot
plot(distr.at, pch=20, cex=2, col="steelblue")
map("world", resolution = 0.5, add=T)

# you could also use function gmap in "dismo"
points.at <- as.data.frame(distr.at)
points.at$x <- distr.at@coords[,"lon"]
points.at$y <- distr.at@coords[,"lat"]
at.map <- gmap(points.at, type="roadmap")

# Google Maps are in Mercator projection
# this function projects the points to that
# projection to enable mapping
distr.at.merc <- Mercator(points.at[,c("x","y")])
plot(at.map)
points(distr.at.merc, pch=20, col="red")
 
### Plotting onto a Google Map using googleVis
library(googleVis)
points.at <- as.data.frame(distr.at)
points.at$latlon <- paste(distr.at@coords[,"lat"], distr.at@coords[,"lon"], sep=":")
map.at <- gvisMap(points.at, locationvar="latlon", tipvar="locality",
                  options = list(showTip=T, showLine=F, enableScrollWheel=TRUE,
                           useMapTypeControl=T, width=700, height=500))
plot(map.at)
print(map.at) # HTML suitable for a web page

### Plotting onto a Google Map using googleVis
library(googleVis)
points <- as.data.frame(distr)
points$latlon <- paste(distr@coords[,"lat"], distr@coords[,"lon"], sep=":")
map <- gvisMap(points, locationvar="latlon", tipvar="locality",
               options = list(showTip=T, showLine=F, enableScrollWheel=TRUE,
                              useMapTypeControl=T, width=600, height=500,
                              maptype="normal"))
plot(map)
print(map)
Something went wrong with that request. Please try again.