library(ggplot2)
library(ggthemes)
library(viridis) # devtools::install_github("sjmgarnier/viridis)
## Loading required package: viridisLite
library(ggmap)
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:viridis':
##
## viridis_pal
library(grid)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(gridExtra)
##
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
##
## combine
library(leaflet.extras)
## Loading required package: leaflet
# rodar mapa_acidentes.R
setwd('~/OneDrive/r-files/sem-foros/')
list.files()
## [1] "endpoints.csv" "endpoints.html" "endpoints.Rmd"
## [4] "index.html" "LICENSE" "README.md"
## [7] "rsconnect" "run.R" "semaforos_jul18.csv"
## [10] "semaforos_jul18.xls" "semaforos.R" "teste.R"
semaforos = read.csv('semaforos_jul18.csv', header = TRUE, sep = ";")
head(semaforos, 10)
class(semaforos$Longitude)
## [1] "numeric"
endpoints = read.csv('~/OneDrive/r-files/sem-foros/endpoints.csv', header = TRUE, sep = ";")
head(endpoints, 10)
sub( '(?<=.{3})', '.', endpoints$LONGITUDE[1], perl=TRUE )
## [1] "-51.100178"
endpoints$LONGITUDE = sub( '(?<=.{3})', '.', endpoints$LONGITUDE, perl=TRUE )
endpoints$LATITUDE = sub( '(?<=.{3})', '.', endpoints$LATITUDE, perl=TRUE )
head(endpoints)
class(endpoints$LONGITUDE)
## [1] "character"
endpoints$LONGITUDE = as.numeric(as.character(endpoints$LONGITUDE))
endpoints$LATITUDE = as.numeric(as.character(endpoints$LATITUDE))
library(wesanderson)
pal <- colorFactor(
#palette = 'Darjeeling', #topo.colors(5),
palette = c("black", "yellow","Blue", "green","red"),
domain = semaforos$TIPO
)
head(dados)
Criando heatmap de acidentes e plotando pontos semafóricos:
#utilizando o dataset dados de mapa_acidentes.R
leaflet(semaforos) %>%
addTiles(group="OSM") %>%
addCircles(~Longitude, ~Latitude, popup=~paste("ID: ", ID,
"<br>Local: ", LOG1, "N?: ", PREDIAL,
"<br>Tipo: ", TIPO,
"<br>ObsS: ", OBSERVACAO,
sep = ""),
weight = 1, radius=20, color= 'red', stroke = TRUE, fillOpacity = 0.8) %>%
addHeatmap(group=dados$LOG1, lng=dados$LONGITUDE, lat=dados$LATITUDE, radius = 15 , max=10, blur = 20, intensity =1) %>%
addLegend("bottomright", colors= "red", labels="JULHO 2018", title="Semáforos:")
Criando heatmap de acidentes e plotando pontos de endpoits:
#utilizando o dataset dados de mapa_acidentes.R
leaflet(endpoints) %>%
addTiles(group="OSM") %>%
addCircles(~LONGITUDE, ~LATITUDE, weight = 1, radius=15, color= '#085BD3', stroke = TRUE, fillOpacity = 0.8) %>%
addHeatmap(group=dados$LOG1, lng=dados$LONGITUDE, lat=dados$LATITUDE, radius = 15 , max=10, blur = 20, intensity =1) %>%
addLegend("bottomright", colors= "#085BD3", labels="JULHO 2018", title="EndPoints:")
#https://www.rdocumentation.org/packages/leaflet.extras/versions/0.2/topics/addHeatmap
pal <- colorFactor(
#palette = 'Darjeeling', #topo.colors(5),
palette = c("black", "yellow","Blue", "green","red"),
domain = semaforos$TIPO
)
leaflet(semaforos) %>%
addTiles(group="OSM") %>%
addHeatmap(group=dados$LOG1, lng=dados$LONGITUDE, lat=dados$LATITUDE, radius = 10 , max=30, blur = 25, intensity =1) %>%
addCircles(~Longitude, ~Latitude, popup=~paste("ID: ", ID,
"<br>Local: ", LOG1, "N?: ", PREDIAL,
"<br>Tipo: ", TIPO,
"<br>ObsS: ", OBSERVACAO,
sep = ""),
weight = 1, radius=20, color= ~pal(TIPO), stroke = TRUE, fillOpacity = 0.8) %>%
addLegend("bottomright", colors= "#ffa500", labels="JULHO 2018", title="SEMÁFOROS:")
pal2 <- colorFactor(
palette = c('red', 'blue', 'green', 'orange'),
domain = semaforos$TIPO
)
leaflet(semaforos) %>%
addTiles(group="OSM") %>%
addCircles(~Longitude, ~Latitude, popup=~paste("ID: ", ID, "<br>Local: ", CDL1, "<br>Tipo: ", TIPO, sep = " "),
weight = 1, radius=20, color= ~pal2(TIPO), stroke = TRUE, fillOpacity = 0.8) %>%
addLegend("bottomright", colors= "#ffa500", labels="JULHO 2018", title="SEMÁFOROS:")
leaflet(semaforos) %>%
addProviderTiles(providers$OpenStreetMap) %>%
addWebGLHeatmap(lng = ~Longitude, lat = ~Latitude, size = 60) %>%
addCircles(lng = ~Longitude, lat = ~Latitude, weight = 1, fillOpacity = 0.5,
radius = 20, color= ~pal(TIPO), group = "cities")
Acidentes em Porto Alegre de 2013:2017
dim(dados)
## [1] 81172 41
#https://www.rdocumentation.org/packages/leaflet.extras/versions/0.2/topics/addHeatmap
pal <- colorFactor(
#palette = 'Darjeeling', #topo.colors(5),
palette = c("black", "yellow","Blue", "green","red"),
domain = dados$TIPO_ACID
)
leaflet(dados) %>%
addTiles(group="OSM") %>%
addHeatmap(group=dados$LOG1, lng=dados$LONGITUDE, lat=dados$LATITUDE, radius = 10 , max=30, blur = 25, intensity =1) %>%
addCircles(~LONGITUDE, ~LATITUDE, popup=~paste("ID: ", ID,
"<br>Local: ", LOCAL_VIA,
"<br>Tipo: ", TIPO_ACID,
"<br>Região: ", REGIAO,
sep = ""),
weight = 1, radius=20, color= ~pal(TIPO_ACID), stroke = TRUE, fillOpacity = 0.8) %>%
addLegend("bottomright", colors= "", labels="2013-2017", title="Acidentes:")