This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
This is to show the top 100 cities to live in by livable wages. The data is found at https://www.kaggle.com/datasets/brandonconrady/living-wage-top-100-cities?resource=download
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(leaflet)
library(readxl)
library(htmltools)
livingwage <- read_excel("E:/School stuff/r/assignment5/livingwage.xlsx")
head(livingwage)
## # A tibble: 6 x 21
## rank city state population_2020 population_2010 land_area_sqmi density
## <dbl> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
## 1 1 New York New ~ 8804190 8175133 300. 29298
## 2 2 Los Angeles Cali~ 3898747 3792621 470. 8304
## 3 3 Chicago Illi~ 2746388 2695598 228. 12061
## 4 4 Houston Texas 2304580 2099451 640. 3599
## 5 5 Phoenix Ariz~ 1608139 1445632 518 3105
## 6 6 Philadelph~ Penn~ 1603797 1526006 134. 11933
## # ... with 14 more variables: one_adult_no_kids_living_wage <dbl>,
## # one_adult_one_kid_living_wage <dbl>, one_adult_two_kids_living_wage <dbl>,
## # one_adult_three_kids_living_wage <dbl>,
## # two_adults_one_working_no_kids_living_wage <dbl>,
## # two_adults_one_working_one_kid_living_wage <dbl>,
## # two_adults_one_working_two_kids_living_wage <dbl>,
## # two_adults_one_working_three_kids_living_wage <dbl>, ...
summary(livingwage)
## rank city state population_2020
## Min. : 1.00 Length:100 Length:100 Min. : 226610
## 1st Qu.: 25.75 Class :character Class :character 1st Qu.: 282217
## Median : 50.50 Mode :character Mode :character Median : 390264
## Mean : 50.50 Mean : 650040
## 3rd Qu.: 75.25 3rd Qu.: 644553
## Max. :100.00 Max. :8804190
## population_2010 land_area_sqmi density
## Min. : 176320 Min. : 14.70 Min. : 171
## 1st Qu.: 246890 1st Qu.: 66.65 1st Qu.: 2498
## Median : 356460 Median : 111.75 Median : 3668
## Mean : 597872 Mean : 178.55 Mean : 4869
## 3rd Qu.: 600424 3rd Qu.: 203.12 3rd Qu.: 5200
## Max. :8175133 Max. :1706.80 Max. :29298
## one_adult_no_kids_living_wage one_adult_one_kid_living_wage
## Min. :12.40 Min. :26.18
## 1st Qu.:13.95 1st Qu.:29.19
## Median :15.08 Median :30.66
## Mean :15.83 Mean :32.65
## 3rd Qu.:16.33 3rd Qu.:33.93
## Max. :25.12 Max. :50.18
## one_adult_two_kids_living_wage one_adult_three_kids_living_wage
## Min. :31.69 Min. :40.57
## 1st Qu.:35.90 1st Qu.:46.61
## Median :38.06 Median :49.12
## Mean :40.59 Mean :52.93
## 3rd Qu.:43.14 3rd Qu.:57.01
## Max. :61.69 Max. :81.63
## two_adults_one_working_no_kids_living_wage
## Min. :20.97
## 1st Qu.:22.95
## Median :24.12
## Mean :25.29
## 3rd Qu.:25.64
## Max. :37.33
## two_adults_one_working_one_kid_living_wage
## Min. :24.94
## 1st Qu.:27.27
## Median :28.98
## Mean :30.28
## 3rd Qu.:31.24
## Max. :44.83
## two_adults_one_working_two_kids_living_wage
## Min. :28.36
## 1st Qu.:30.89
## Median :32.41
## Mean :33.95
## 3rd Qu.:34.93
## Max. :48.81
## two_adults_one_working_three_kids_living_wage
## Min. :30.46
## 1st Qu.:33.51
## Median :35.33
## Mean :37.51
## 3rd Qu.:38.75
## Max. :56.53
## two_adults_both_working_no_kids_living_wage
## Min. :10.15
## 1st Qu.:11.12
## Median :11.85
## Mean :12.28
## 3rd Qu.:12.60
## Max. :17.37
## two_adults_both_working_one_kid_living_wage
## Min. :14.39
## 1st Qu.:16.01
## Median :16.64
## Mean :17.76
## 3rd Qu.:18.39
## Max. :26.68
## two_adults_both_working_two_kids_living_wage
## Min. :17.61
## 1st Qu.:19.93
## Median :20.94
## Mean :22.21
## 3rd Qu.:23.51
## Max. :32.93
## two_adults_both_working_three_kids_living_wage Latitude
## Min. :20.36 Min. :21.31
## 1st Qu.:23.45 1st Qu.:33.40
## Median :24.72 Median :36.17
## Mean :26.61 Mean :36.58
## 3rd Qu.:28.68 3rd Qu.:39.75
## Max. :41.05 Max. :61.22
## Longitude
## Min. :-157.86
## 1st Qu.:-115.12
## Median : -96.75
## Mean : -98.77
## 3rd Qu.: -83.03
## Max. : -71.06
rkmap <- data.frame(Rank = livingwage$rank,
City = livingwage$city,
State = livingwage$state,
Latitude = livingwage$Latitude,
Longitude = livingwage$Longitude
)
map <- rkmap %>%
leaflet() %>%
addTiles() %>%
addMarkers(popup=paste
("<br>State: ",
htmlEscape(rkmap$State),
"<br>City: ",
htmlEscape(rkmap$City),
"<br>Rank: ",
formatC(livingwage$rank, format = "d", big.mark = ",")
)
)
## Assuming "Longitude" and "Latitude" are longitude and latitude, respectively
map