-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_maps.R
35 lines (29 loc) · 1.03 KB
/
generate_maps.R
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
##This short script will help you getting hands-on with the database
##and plot locations in a map
#Load the database
data<-read.csv("ColombiaBirdMorphologyPhenology.csv", header = T)
attach(data)
head(data)
#Setting geographic coordinates space
min(data$decimalLatitude)
max(data$decimalLatitude)
min(data$decimalLongitude)
max(data$decimalLongitude)
#Ploting a simple map, locating the sampling points in Colombia
library(maps)
library(mapdata)
library(maptools)
library(mapproj)
map(database= "world", ylim=c(4.9, 5.7), xlim=c(-74.5, -76), col="darkgoldenrod1", fill=TRUE, projection="gilbert", orientation= c(90,0,225))
lon <- (data$decimalLongitude)
lat <- (data$decimalLatitude)
coord <- mapproject(lon, lat, proj="gilbert", orientation=c(90, 0, 225)) #convert points to projected lat/long
points(coord, pch=20, cex=1.2, col="red") #plot converted points
# getting the map
library(ggplot2)
library(ggmap)
library(sp)
library(leaflet)
df <- as.data.frame(cbind(lon,lat))
coordinates(df) <- ~lon+lat
leaflet(df) %>% addMarkers() %>% addTiles()