library(stars)
## Warning: package 'stars' was built under R version 4.0.5
## Loading required package: abind
## Warning: package 'abind' was built under R version 4.0.3
## Loading required package: sf
## Warning: package 'sf' was built under R version 4.0.5
## Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1; sf_use_s2() is TRUE
library(lubridate)
## Warning: package 'lubridate' was built under R version 4.0.5
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.0.5
## 
## 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
saludespacial <- st_read('~/modelacion/ESPACIAL/6_CENTROS_SALUD.shp')
## Reading layer `6_CENTROS_SALUD' from data source 
##   `C:\Users\samca\Documents\modelacion\ESPACIAL\6_CENTROS_SALUD.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 39 features and 8 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: -64.98158 ymin: -22.00043 xmax: -64.439 ymax: -21.342
## Geodetic CRS:  WGS 84
plot(saludespacial)

str(saludespacial)
## Classes 'sf' and 'data.frame':   39 obs. of  9 variables:
##  $ gml_id    : chr  "Establecimientos.1985" "Establecimientos.1986" "Establecimientos.1987" "Establecimientos.1988" ...
##  $ ID        : num  1985 1986 1987 1988 1989 ...
##  $ TIPO      : chr  "6" "4" "3" "3" ...
##  $ TIPO_DESCR: chr  "Centro de Salud con Camas" "Puesto de Salud" "Centro de Salud" "Centro de Salud" ...
##  $ NOMBRE_EST: chr  "C.S. 15 DE NOVIEMBRE" "P.S. JUNACAS" "P.S. LA PINTADA" "P.S. PAMPA REDONDA" ...
##  $ LAT       : num  -21.5 -21.4 -21.6 -21.7 -21.7 ...
##  $ LONG      : num  -64.7 -64.4 -64.6 -64.8 -64.9 ...
##  $ CODIGO_SNI: chr  "600002" "600003" "600004" "600005" ...
##  $ geometry  :sfc_POINT of length 39; first list element:  'XY' num  -64.7 -21.5
##  - attr(*, "sf_column")= chr "geometry"
##  - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA
##   ..- attr(*, "names")= chr [1:8] "gml_id" "ID" "TIPO" "TIPO_DESCR" ...
datsalud <- readxl::read_excel('~/SEMESTRE 1.22/Datos_Salud_2011_Rivera_Nicole.xlsx')


unionsalud <- full_join(saludespacial,datsalud, by='NOMBRE_EST')


library(highcharter)
## Warning: package 'highcharter' was built under R version 4.0.5
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
Salud11 <- readxl::read_excel('~/SEMESTRE 1.22/Datos_Salud_2011_Rivera_Nicole.xlsx','Hoja2')

hchart(Salud11, 'heatmap', hcaes(x= EDAD, y= NOMBRE_EST, value= VALOR)) %>% 
  hc_colorAxis(stops= color_stops(10, rev(RColorBrewer::brewer.pal(10,'PuRd')))) %>% 
  hc_tooltip(shared= TRUE, bordercolor= 'black', ValueDecimals=2) %>% 
  hc_exporting(enabled= TRUE, filename= 'SaludTarija')
## Warning in RColorBrewer::brewer.pal(10, "PuRd"): n too large, allowed maximum for palette PuRd is 9
## Returning the palette you asked for with that many colors
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.0.5
paletasalud <- colorBin('magma', domain =unionsalud$TV21Aa59A, bins = 4 )    

leaflet(unionsalud) %>%
  addTiles() %>% 
   addCircleMarkers(fillColor = ~paletasalud(unionsalud$`TV 21 a 59 años`), radius = 1,
                    opacity = 1, fillOpacity = 1, label = unionsalud$`TV 21 a 59 años`)
## Warning in validateCoords(lng, lat, funcName): Data contains 37 rows with either
## missing or invalid lat/lon values and will be ignored
leaflet(unionsalud) %>% 
  addTiles() %>% 
  addMarkers(clusterOptions = markerClusterOptions(),
             label = unionsalud$NOMBRE_EST,
             labelOptions = labelOptions(noHide = T),
             popup = unionsalud$`TV 21 a 59 años`)
## Warning in validateCoords(lng, lat, funcName): Data contains 37 rows with either
## missing or invalid lat/lon values and will be ignored