library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.2     v dplyr   1.0.6
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(leaflet)
library(maptools)
## Loading required package: sp
## Checking rgeos availability: TRUE
library(leaflet.extras)
library(knitr)
library(readxl)
library(rmarkdown)

#Leonel Salazar 
#July 3, 2021
#my Rpubs name is Benderx7

#I really tried to add a few layers onto the information.
#I did a 2021 gdp (estimated) by state. I could not figure out how to add a legend. but i think its pretty cool to see how different layers can clash or comlpiment each other. 
#It was a bit of a struggle to get the long/lat information. 

setwd("C:/Users/runne/Desktop/Intro To R/")
dat <-  read_excel("C:/Users/runne/Desktop/Intro To R/StateGDP2.xlsx")

str(dat)
## tibble [50 x 5] (S3: tbl_df/tbl/data.frame)
##  $ State      : chr [1:50] "Alabama" "Alaska" "Arizona" "Arkansas" ...
##  $ Longitude  : num [1:50] -86.9 -153.4 -111.1 -92.2 -119.4 ...
##  $ Latitude   : num [1:50] 32.3 66.2 34 34.8 36.8 ...
##  $ 2021 Q1 GDP: num [1:50] 6.8 5.4 7.4 6.9 6.3 7.9 6 5.6 7 4.5 ...
##  $ Ranking    : num [1:50] 20 42 9 17 29 5 34 40 15 14 ...
dat <- dat[!is.na(dat$Longitude)&!is.na(dat$Latitude),]



dat %>% 
  leaflet() %>% 
  addTiles()%>%
  addHeatmap(lng = ~Longitude, lat = ~Latitude, intensity = dat$`2021 Q1 GDP`, max = 100, radius = 40, blur = 0)%>%
  addMarkers(popup = dat$State, label = ~`2021 Q1 GDP`, clusterOptions=markerClusterOptions())
## Assuming "Longitude" and "Latitude" are longitude and latitude, respectively