Load library

Load the processed weighted data into R

library(readr)
data <- read_csv("fifty_ten_2000_20_df.csv")

# Making statefp character for easy merging
data$STATEFP<-as.character(data$STATEFP)
state_and_data <- states(2021) %>%
filter(!STATEFP %in% c("02", "11", "15", "60", "66", "69", "72", "78")) %>% # Removed Alaska(02), Hawai(11), DC(15)
#filter(!STATEFP %in% c("02", "15", "60", "66", "69", "72", "78")) %>%
  shift_geometry() %>% 
  left_join(data, by="STATEFP") %>% # join by statefp
  select("STATEFP", "stname", "year_2000", "year_2020", "geometry", "stusps") #select only needed variabe
## Retrieving data for the year 2021
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |                                                                      |   1%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   8%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |===========                                                           |  15%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |==============                                                        |  19%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |=================                                                     |  25%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |===================                                                   |  28%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  29%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |=====================                                                 |  31%
  |                                                                            
  |======================                                                |  32%
  |                                                                            
  |=======================                                               |  32%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |=======================                                               |  34%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |========================                                              |  35%
  |                                                                            
  |=========================                                             |  35%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |==========================                                            |  36%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |==========================                                            |  38%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |===========================                                           |  39%
  |                                                                            
  |============================                                          |  39%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |============================                                          |  41%
  |                                                                            
  |=============================                                         |  41%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |==============================                                        |  42%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |==============================                                        |  44%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |=================================                                     |  46%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |===================================                                   |  51%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |====================================                                  |  52%
  |                                                                            
  |=====================================                                 |  52%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |========================================                              |  58%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==========================================                            |  59%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |==========================================                            |  61%
  |                                                                            
  |===========================================                           |  61%
  |                                                                            
  |===========================================                           |  62%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |============================================                          |  63%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |=============================================                         |  65%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |================================================                      |  68%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |=================================================                     |  71%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |===================================================                   |  72%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |====================================================                  |  74%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |=====================================================                 |  75%
  |                                                                            
  |=====================================================                 |  76%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |=======================================================               |  79%
  |                                                                            
  |=========================================================             |  82%
  |                                                                            
  |==========================================================            |  82%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |===========================================================           |  85%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |==============================================================        |  88%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |===============================================================       |  89%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |===============================================================       |  91%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |=================================================================     |  92%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |===================================================================   |  95%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |====================================================================  |  98%
  |                                                                            
  |===================================================================== |  98%
  |                                                                            
  |======================================================================| 100%
## Warning: None of your features are in Alaska, Hawaii, or Puerto Rico, so no geometries will be shifted.
## Transforming your object's CRS to 'ESRI:102003'

2000 Map

gc()
##           used  (Mb) gc trigger  (Mb) limit (Mb) max used  (Mb)
## Ncells 5014049 267.8    8389494 448.1         NA  8389494 448.1
## Vcells 9317204  71.1   17824054 136.0      16384 17754580 135.5
tmap_mode("plot")
## tmap mode set to plotting
tm_basemap("OpenStreetMap.Mapnik")+
  tm_shape(state_and_data)+
  tm_polygons("year_2000",  
              #style="kmeans", # natural r way of scallin
              title=c("Income Inequality Ratio"),
              palette="Blues",
              #n=8, # works with style line
              breaks=c(4.2, 4.7, 5.2, 5.7, 6.2, 6.7),
              legend.hist = TRUE) +
  tm_text("stusps",
          size = 0.5) +
  tm_layout(legend.outside = TRUE,
            title = "50/10 Individual Income Inequality Ratio  \n US STATEs 2000",
            title.size =1.5,
            legend.frame = TRUE,
            ) +  tm_compass(position = c("right","top")) + tm_format("World",
            legend.position =  c("left", "bottom"),
            main.title.position =c("center")) + tm_scale_bar(position = c("left","bottom"))

2020 Map

gc()
##           used  (Mb) gc trigger  (Mb) limit (Mb) max used  (Mb)
## Ncells 5169375 276.1    8389494 448.1         NA  8389494 448.1
## Vcells 9630802  73.5   27202776 207.6      16384 27133029 207.1
tmap_mode("plot")
## tmap mode set to plotting
tm_basemap("OpenStreetMap.Mapnik")+
  tm_shape(state_and_data)+
  tm_polygons("year_2020",  
              #style="kmeans",
              title=c("Income Inequality Ratio"),
              palette="Blues",
              #n=8,
              breaks=c(4.2, 4.7, 5.2, 5.7, 6.2, 6.7),
              legend.hist = TRUE) +
  tm_text("stusps",
          size = 0.5) +
  tm_layout(legend.outside = TRUE,
            title = "50/10 Individual Income Inequality Ratio  \n US STATEs 2020",
            title.size =1.5,
            legend.frame = TRUE,
            ) +  tm_compass(position = c("right","top")) + tm_format("World",
            legend.position =  c("left", "bottom"),
            main.title.position =c("center")) + tm_scale_bar(position = c("left","bottom"))

Additional Map

Plotting Changes from 2000 to 2020

library(dplyr)

state_and_data$year_2000<- as.numeric(state_and_data$year_2000)
state_and_data$year_2020<- as.numeric(state_and_data$year_2020)

state_and_data <- state_and_data %>%
  mutate(changes = case_when(
    year_2000 < year_2020 ~ "Increased",
    year_2000 > year_2020 ~ "Decreased",
    TRUE ~ "No Changes"
  ))
gc()
##           used  (Mb) gc trigger  (Mb) limit (Mb) max used  (Mb)
## Ncells 5175853 276.5    8389494 448.1         NA  8389494 448.1
## Vcells 9645738  73.6   32723331 249.7      16384 27199506 207.6
tmap_mode("plot")
## tmap mode set to plotting
tm_basemap("OpenStreetMap.Mapnik") +
  tm_shape(state_and_data) +
  tm_polygons("changes",
              title = "Income Inequality Ratio",
              palette = c("#ADD8E6", "#FFB6C1", "grey"),  # Specify colors for each category
              #labels = c("Decrease", "Increase", "No Change"),  # Label categories
              legend.show = TRUE) +
  tm_text("stusps", size = 0.5) +
  tm_layout(legend.outside = TRUE,
            title = "50/10 Individual Income Inequality Ratio\nUS STATES 2000-2020 changes",
            title.size = 1.5,
            legend.frame = TRUE) +
  tm_compass(position = c("right", "top")) +
  tm_format("World",
            legend.position = c("left", "bottom"),
            main.title.position = c("center")) +
  tm_scale_bar(position = c("left", "bottom"))