rm(list = ls())
library(tidyverse)
## -- Attaching packages ---------------------------------------------------------------------------- tidyverse 1.2.0 --
## v ggplot2 2.2.1     v purrr   0.2.3
## v tibble  1.3.4     v dplyr   0.7.4
## v tidyr   0.7.1     v stringr 1.2.0
## v readr   1.1.1     v forcats 0.2.0
## -- Conflicts ------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(httr)
library(geojsonio)
## 
## Attaching package: 'geojsonio'
## The following object is masked from 'package:base':
## 
##     pretty
library(highcharter)
## Highcharts (www.highcharts.com) is a Highsoft software product which is
## not free for commercial and Governmental use
mapa <- "https://raw.githubusercontent.com/juaneladio/peru-geojson/master/peru_departamental_simple.geojson" %>% 
  GET() %>% 
  content() %>% 
  jsonlite::fromJSON(simplifyVector = FALSE)

# Extraemos lo que tiene de información
data <- map_df(mapa$features, "properties")
data <- mutate(data, value = COUNT)
data
## # A tibble: 25 x 5
##         NOMBDEP COUNT FIRST_IDDP   HECTARES value
##           <chr> <int>      <chr>      <dbl> <int>
##  1     AMAZONAS    84         01 3930646.57    84
##  2       ANCASH   166         02 3596224.60   166
##  3     APURIMAC    80         03 2111415.17    80
##  4     AREQUIPA   109         04 6325588.93   109
##  5     AYACUCHO   111         05 4350381.78   111
##  6    CAJAMARCA   127         06 3304465.55   127
##  7       CALLAO     6         07   14140.95     6
##  8        CUSCO   108         08 7207614.24   108
##  9 HUANCAVELICA    94         09 2206503.88    94
## 10      HUANUCO    76         10 3720052.60    76
## # ... with 15 more rows
highchart(type = "map") %>% 
  hc_add_series(mapData = mapa, showInLegend = TRUE, data = data,
                joinBy = "FIRST_IDDP", name = "Hectareas") %>% 
  hc_colorAxis(enabled = TRUE) %>% 
  # acá accedes a los valores del data frame "data"
  hc_tooltip(pointFormat = "{point.NOMBDEP}: {point.value}")