packageList<-c('tidyverse','leaflet','data.table','rgdal','ggplot2','deldir','sp','RColorBrewer','KernSmooth','googleway')
sapply(packageList, FUN = require, character.only=TRUE)
motoMap<- readOGR("C:/Users/ming0/OneDrive/Escritorio/Motos")
ComunasR13Map<-readOGR("C:/Users/ming0/OneDrive/Escritorio/Motos/R13")
plot(motoMap)
plot(ComunasR13Map,add=T)
leaflet(motoMap)%>%
addTiles()%>%
addMarkers()
leaflet(ComunasR13Map)%>%
addTiles()%>%
addPolygons()
leaflet(ComunasR13Map)%>%
addTiles()%>%
addPolygons()%>%
addMarkers(motoMap,lng = motoMap@coords[,1],lat = motoMap@coords[,2])
head(ComunasR13Map@data)
head(motoMap@data)
table(ComunasR13Map@data$COMUNA%in%motoMap@data$COD_COMUNA)
ComunasR13Mapmoto<-ComunasR13Map[ComunasR13Map@data$COMUNA%in%motoMap@data$COD_COMUNA,]
leaflet(ComunasR13Mapmoto)%>%
addTiles()%>%
addPolygons()%>%
addMarkers(motoMap,lng = motoMap@coords[,1],lat = motoMap@coords[,2])
class(motoMap@data)
motoData<-data.table(motoMap@data)
NumAccMoto<-motoData[,.(NumAccMoto=.N),by=.(COD_COMUNA)]
ComunasR13Mapmoto@data<-merge(ComunasR13Mapmoto@data,NumAccMoto,by.x="COMUNA",by.y="COD_COMUNA",sort=F,all.x=T)
head(ComunasR13Mapmoto@data)
head(NumAccMoto)
Colores<-colorQuantile(palette = brewer.pal(4,name = "Reds"),domain =range(ComunasR13Mapmoto@data$NumAccMoto,na.rm = T),n = 5)
labels <- sprintf(
"<strong>Comuna: %s </strong><br/>: %g ",
ComunasR13Mapmoto$NOM_COMUNA, ComunasR13Mapmoto$NumAccMoto
) %>% lapply(htmltools::HTML)
class(motoMap@data)
motoData<-data.table(motoMap@data)
motoData[,.N,by=.(COMUNA1)]
motoMapStgo<-motoMap[motoMap$COMUNA1=="SANTIAGO" | motoMap$COMUNA1=="LAS CONDES" ,]
leaflet(motoMapStgo)%>%
addProviderTiles(provider = "CartoDB")%>%
addMarkers()
Las condes posee 215 accidentes: aqui se explaya en chench
Santiago posee 321 accidentes: aqui se explaya el chench