--- title: "Choropleth Maps and Heatmaps" author: "Prof. Eric A. Suess" date: "November 9, 2022" output: ioslides_presentation: default beamer_presentation: default --- ## Chloropleth maps and Heatmaps Today we will discuss the use of choropleth maps and heatmaps. **Choropleth** maps add color to states relative to a variable. **Heatmaps** visual the values in a matrix by add color relative to a variable(s), usually down columns. ## Choropleth maps The R packages *choroplethr* and *choroplethrMaps* can be used to make choropleth maps. To learn about this package consider taking the [free course](https://arilamstein.com/open-source/) ## Choropleth maps ```{r message=FALSE} library(tidyverse) library(choroplethr) library(choroplethrMaps) data(df_pop_state) head(df_pop_state, 15) ``` ## Choropleth maps ```{r} state_choropleth(df_pop_state, title = "US 2012 State Population Estimates", legend = "Population") ``` ## Heatmap ```{r} data(df_state_demographics) # head(df_state_demographics) df_state_demographics <- df_state_demographics %>% arrange(total_population) X <- data.matrix(df_state_demographics[,2:8]) row.names(X) <- df_state_demographics[,1] head(X) ``` ## Heatmap using base R ```{r} heatmap(X, Rowv=NA, Colv=NA, col = cm.colors(256), scale = "column") ``` ## Heatmap using base R ```{r} heatmap(X, Rowv=NA, Colv=NA, col = heat.colors(256), scale = "column") ``` ## Heatmap using base R ```{r} library(RColorBrewer) heatmap(X, Rowv=NA, Colv=NA, col = brewer.pal(9, "Blues"), scale = "column") ``` ## Heatmaply, using plotyly ```{r message=FALSE} library(plotly) library(heatmaply) heatmaply(X,scale = "col") ``` ## shinyHeatmaply, using plotyly ```{r eval=FALSE} library(shinyHeatmaply) launch_heatmaply(X) ``` ## Shiny Heatmap Check out the [shinyheatmap](http://shinyheatmap.com/) webpage.