-
Notifications
You must be signed in to change notification settings - Fork 113
/
R - Geolocation Brazil
62 lines (52 loc) · 1.87 KB
/
R - Geolocation Brazil
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
57
58
59
60
61
62
closeAllConnections()
rm(list=ls())
setwd("/Volumes/16 DOS/R_nbs")
library(maptools)
library(ggplot2)
library(rgdal)
library(rgeos)
library(ggmap)
# read administrative boundaries (change folder appropriately)
brMap <- readShapePoly("Google/BRASIL.shp")
# read downloaded data (change folder appropriately)
brRen <- read.csv("Google/Renda.csv", sep = ";", quote = "\"", dec=".", stringsAsFactors = FALSE)
brRen$rendapc <- as.numeric(as.character(brRen$rendapc)) # format as numeric
brRen$rendapc
brRen
#convert shp to UTF8
library(descr)
brMap$ESTADO<-toUTF8(brMap$ESTADO, "IBM850")
brMap$ESTADO
# convert shp data to data frame for ggplot
as.data.frame(brMap) # para definir a region
brMap = gBuffer(brMap, width=0, byid=TRUE) #correct problem with Polygons - TopologyException
library("gpclib")
brMapDf <- fortify(brMap, region="UF")
brMapDf$lat
# merge map and data
brRenMapDf <- merge(brMapDf, brRen, by.x="id", by.y="Iden")
brRenMapDf <- brRenMapDf[order(brRenMapDf$order),]
# limit data to main Europe
brazil.limits <- geocode(c("Monte Caburaí", "Barra do Chuí", "Serra do Divisor", "Ilhas Martin Vaz"))
brazil.limits
brRenMapDf <- subset(brRenMapDf, long > min(brazil.limits$lon) & long < max(brazil.limits$lon) & lat > min(brazil.limits$lat) & lat < max(brazil.limits$lat))
xx<-cbind(data.frame(c(-65,-60)),data.frame(c(-12,-11)),data.frame(c("A","B")))
colnames(xx)<-c("x","y","group")
str(xx)
str(brMapDf)
xx
csv<-read.csv("cepbr_geo.csv",sep=",",header=TRUE)
head(csv)
str(csv)
# OPTION 1
library("ggmap")
library("leaflet")
place<-ggmap::geocode("São Paulo")
place
m<-leaflet(place) %>% addTiles() %>% setView(place$lon,place$lat,zoom=10)
m
marker<-makeIcon(
iconUrl = "http://www.clker.com/cliparts/F/w/l/C/e/W/map-marker.svg",
iconWidth = 38, iconHeight = 60,
iconAnchorX = 22, iconAnchorY = 94)
addMarkers(data=csv,lat=runif(100,-24,-23),lng=runif(100,-47,-46),map=m,icon=marker)