Skip to content

Instantly share code, notes, and snippets.

@smach

smach/MassDataByZipCode.Rmd Secret

Created Apr 29, 2019
Embed
What would you like to do?
---
title: "Massachusetts Data by Zip Code"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
if(!require("pacman")){
install.packages("pacman")
}
pacman::p_load(DT, dplyr, ggplot2, scales)
markdowndata <- data.frame(stringsAsFactors=FALSE,
ZipCode = c("01001", "01002", "01002", "01003", "01005",
"01007", "01008", "01009", "01010", "01011",
"01011", "01012", "01013", "01020", "01022",
"01026", "01027", "01028", "01029", "01030",
"01031", "01032", "01033", "01034", "01035",
"01036", "01037", "01038", "01039", "01039",
"01040", "01050", "01050", "01053", "01054",
"01056", "01057", "01060", "01062", "01063",
"01066", "01068", "01069", "01070", "01071",
"01072", "01073", "01074", "01075", "01077",
"01079", "01080", "01081", "01082", "01082", "01082",
"01082", "01083", "01084", "01085", "01086",
"01088", "01089", "01092", "01093", "01094",
"01095", "01096", "01097", "01098", "01103",
"01104", "01105", "01106", "01107", "01108",
"01109", "01118", "01119", "01128", "01129",
"01151", "01199", "01201", "01220", "01222",
"01223", "01224", "01225", "01226", "01229",
"01230", "01235", "01236", "01237", "01238",
"01240", "01242", "01243", "01244", "01245", "01247",
"01253", "01254", "01255", "01256", "01257",
"01258", "01259", "01260", "01262", "01264",
"01266", "01267", "01270", "01301", "01330",
"01331", "01337", "01338", "01339", "01340",
"01341", "01342", "01343", "01344", "01346",
"01347", "01349", "01350", "01351", "01354",
"01355", "01360", "01364", "01366", "01367",
"01368", "01370", "01373", "01375", "01376",
"01378", "01379", "01420", "01430", "01431", "01432",
"01434", "01434", "01434", "01434", "01436",
"01438", "01440", "01450", "01451", "01452",
"01453", "01460", "01462", "01463", "01464",
"01467", "01468", "01469", "01473", "01474",
"01475", "01501", "01503", "01504", "01505",
"01506", "01507", "01510", "01515", "01516",
"01518", "01519", "01520", "01521", "01522",
"01523", "01524", "01525", "01527", "01529",
"01531", "01532", "01534", "01535", "01536", "01537",
"01540", "01541", "01542", "01543", "01545",
"01550", "01560", "01561", "01562", "01564",
"01566", "01568", "01569", "01570", "01571",
"01581", "01583", "01585", "01588", "01590",
"01602", "01603", "01604", "01605", "01606",
"01607", "01608", "01609", "01610", "01611",
"01612", "01701", "01702", "01718", "01719",
"01720", "01721", "01730", "01731", "01740",
"01741", "01742", "01745", "01746", "01747", "01748",
"01749", "01752", "01754", "01756", "01757",
"01760", "01770", "01772", "01773", "01775",
"01776", "01778", "01801", "01803", "01810",
"01821", "01824", "01826", "01827", "01830",
"01832", "01833", "01834", "01835", "01840",
"01841", "01843", "01844", "01845", "01850",
"01851", "01852", "01854", "01860", "01862",
"01863", "01864", "01867", "01876", "01879",
"01880", "01886", "01887", "01890", "01901", "01902",
"01904", "01905", "01906", "01907", "01908",
"01913", "01915", "01921", "01922", "01923",
"01929", "01930", "01937", "01938", "01940",
"01940", "01944", "01945", "01949", "01950",
"01951", "01952", "01960", "01966", "01969",
"01970", "01982", "01983", "01984", "01985",
"02019", "02021", "02025", "02026", "02030",
"02032", "02035", "02038", "02043", "02045",
"02047", "02048", "02050", "02052", "02053", "02054",
"02056", "02061", "02062", "02066", "02067",
"02071", "02072", "02081", "02090", "02093",
"02108", "02109", "02110", "02111", "02113",
"02114", "02115", "02116", "02118", "02119",
"02120", "02121", "02122", "02124", "02125",
"02126", "02127", "02128", "02129", "02130",
"02131", "02132", "02134", "02135", "02136",
"02138", "02139", "02140", "02141", "02142",
"02143", "02144", "02145", "02148", "02149", "02149",
"02150", "02151", "02152", "02155", "02163",
"02169", "02170", "02171", "02176", "02180",
"02184", "02186", "02188", "02189", "02190",
"02191", "02199", "02203", "02210", "02215",
"02215", "02301", "02302", "02322", "02324",
"02330", "02332", "02333", "02338", "02339",
"02341", "02343", "02346", "02347", "02351",
"02356", "02357", "02359", "02360", "02364",
"02366", "02367", "02368", "02370", "02375", "02379",
"02382", "02420", "02421", "02445", "02446",
"02451", "02452", "02453", "02457", "02458",
"02459", "02460", "02461", "02462", "02464",
"02465", "02466", "02467", "02467", "02467",
"02468", "02472", "02474", "02476", "02478",
"02481", "02482", "02492", "02493", "02494",
"02532", "02532", "02532", "02532", "02534",
"02535", "02536", "02537", "02538", "02539",
"02540", "02542", "02543", "02543", "02553", "02554",
"02556", "02557", "02558", "02559", "02561",
"02562", "02563", "02564", "02568", "02571",
"02575", "02576", "02584", "02601", "02630",
"02631", "02632", "02633", "02635", "02637",
"02638", "02639", "02641", "02642", "02643",
"02644", "02645", "02646", "02647", "02648",
"02649", "02650", "02651", "02652", "02653",
"02655", "02657", "02659", "02660", "02663",
"02664", "02666", "02667", "02668", "02669", "02670",
"02671", "02672", "02673", "02675", "02702",
"02703", "02713", "02715", "02717", "02718",
"02719", "02720", "02721", "02723", "02724",
"02725", "02726", "02738", "02739", "02740",
"02743", "02744", "02745", "02746", "02747",
"02748", "02760", "02762", "02763", "02764",
"02766", "02767", "02769", "02770", "02771",
"02777", "02779", "02780", "02790", "02791"),
City = c("Agawam", "Amherst", "Amherst", "Amherst",
"Barre", "Belchertown", "Blandford",
"Bondsville", "Brimfield", "Chester", "Chester",
"Chesterfield", "Chicopee", "Chicopee",
"Chicopee", "Cummington", "Easthampton",
"East Longmeadow", "East Otis", "Feeding Hills",
"Gilbertville", "Goshen", "Granby", "Granville", "Hadley",
"Hampden", "Hardwick", "Hatfield",
"Haydenville", "Haydenville", "Holyoke", "Huntington",
"Huntington", "Leeds", "Leverett", "Ludlow",
"Monson", "Northampton", "Florence",
"Northampton", "North Hatfield", "Oakham", "Palmer",
"Plainfield", "Russell", "Shutesbury",
"Southampton", "South Barre", "South Hadley",
"Southwick", "Thorndike", "Three Rivers", "Wales",
"Ware", "Ware", "Ware", "Ware", "Warren",
"West Chesterfield", "Westfield", "Westfield",
"West Hatfield", "West Springfield", "West Warren",
"Whately", "Wheelwright", "Wilbraham",
"Williamsburg", "Woronoco", "Worthington",
"Springfield", "Springfield", "Springfield", "Longmeadow",
"Springfield", "Springfield", "Springfield",
"Springfield", "Springfield", "Springfield",
"Springfield", "Indian Orchard", "Springfield",
"Pittsfield", "Adams", "Ashley Falls",
"Becket", "Berkshire", "Cheshire", "Dalton",
"Glendale", "Great Barrington", "Hinsdale",
"Housatonic", "Lanesboro", "Lee", "Lenox", "Lenox Dale",
"Middlefield", "Mill River", "Monterey",
"North Adams", "Otis", "Richmond", "Sandisfield",
"Savoy", "Sheffield", "South Egremont",
"Southfield", "South Lee", "Stockbridge",
"Tyringham", "West Stockbridge", "Williamstown",
"Windsor", "Greenfield", "Ashfield", "Athol",
"Bernardston", "Buckland", "Charlemont", "Colrain",
"Conway", "Deerfield", "Drury", "Erving",
"Heath", "Lake Pleasant", "Millers Falls",
"Monroe Bridge", "Montague", "Gill", "New Salem",
"Northfield", "Orange", "Petersham", "Rowe",
"Royalston", "Shelburne Falls", "South Deerfield",
"Sunderland", "Turners Falls", "Warwick",
"Wendell", "Fitchburg", "Ashburnham", "Ashby",
"Ayer", "Devens", "Devens", "Devens", "Devens",
"Baldwinville", "East Templeton", "Gardner",
"Groton", "Harvard", "Hubbardston",
"Leominster", "Littleton", "Lunenburg", "Pepperell",
"Shirley", "Still River", "Templeton", "Townsend",
"Westminster", "West Townsend", "Winchendon",
"Auburn", "Berlin", "Blackstone", "Boylston",
"Brookfield", "Charlton", "Clinton",
"East Brookfield", "Douglas", "Fiskdale", "Grafton",
"Holden", "Holland", "Jefferson", "Lancaster",
"Leicester", "Linwood", "Millbury",
"Millville", "New Braintree", "Northborough",
"Northbridge", "North Brookfield", "North Grafton",
"North Oxford", "Oxford", "Princeton", "Rochdale",
"Rutland", "Shrewsbury", "Southbridge",
"South Grafton", "South Lancaster", "Spencer",
"Sterling", "Sturbridge", "Upton", "Uxbridge",
"Webster", "Dudley", "Westborough",
"West Boylston", "West Brookfield", "Whitinsville",
"Sutton", "Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Cherry Valley",
"Paxton", "Framingham", "Framingham",
"Village of Nagog Woods", "Boxborough", "Acton",
"Ashland", "Bedford", "Hanscom Afb", "Bolton",
"Carlisle", "Concord", "Fayville", "Holliston",
"Hopedale", "Hopkinton", "Hudson", "Marlborough",
"Maynard", "Mendon", "Milford", "Natick",
"Sherborn", "Southborough", "Lincoln", "Stow",
"Sudbury", "Wayland", "Woburn", "Burlington",
"Andover", "Billerica", "Chelmsford", "Dracut",
"Dunstable", "Haverhill", "Haverhill",
"Georgetown", "Groveland", "Haverhill", "Lawrence",
"Lawrence", "Lawrence", "Methuen",
"North Andover", "Lowell", "Lowell", "Lowell", "Lowell",
"Merrimac", "North Billerica",
"North Chelmsford", "North Reading", "Reading", "Tewksbury",
"Tyngsboro", "Wakefield", "Westford",
"Wilmington", "Winchester", "Lynn", "Lynn", "Lynn",
"Lynn", "Saugus", "Swampscott", "Nahant",
"Amesbury", "Beverly", "Boxford", "Byfield",
"Danvers", "Essex", "Gloucester", "Hathorne",
"Ipswich", "Lynnfield", "Lynnfield", "Manchester",
"Marblehead", "Middleton", "Newburyport",
"Newbury", "Salisbury", "Peabody", "Rockport",
"Rowley", "Salem", "South Hamilton", "Topsfield",
"Wenham", "West Newbury", "Bellingham", "Canton",
"Cohasset", "Dedham", "Dover",
"East Walpole", "Foxboro", "Franklin", "Hingham", "Hull",
"Humarock", "Mansfield", "Marshfield",
"Medfield", "Medway", "Millis", "Norfolk", "Norwell",
"Norwood", "Scituate", "Sharon",
"South Walpole", "Stoughton", "Walpole", "Westwood",
"Wrentham", "Boston", "Boston", "Boston", "Boston",
"Boston", "Boston", "Boston", "Boston",
"Boston", "Roxbury", "Roxbury Crossing",
"Dorchester", "Dorchester", "Dorchester Center",
"Dorchester", "Mattapan", "Boston", "Boston",
"Charlestown", "Jamaica Plain", "Roslindale",
"West Roxbury", "Allston", "Brighton", "Hyde Park",
"Cambridge", "Cambridge", "Cambridge",
"Cambridge", "Cambridge", "Somerville", "Somerville",
"Somerville", "Malden", "Everett", "Everett",
"Chelsea", "Revere", "Winthrop", "Medford",
"Boston", "Quincy", "Quincy", "Quincy", "Melrose",
"Stoneham", "Braintree", "Milton",
"Weymouth", "East Weymouth", "South Weymouth",
"North Weymouth", "Boston", "Boston", "Boston",
"Boston", "Boston", "Brockton", "Brockton", "Avon",
"Bridgewater", "Carver", "Duxbury",
"East Bridgewater", "Halifax", "Hanover", "Hanson",
"Holbrook", "Middleboro", "Lakeville", "Abington",
"North Easton", "North Easton", "Pembroke",
"Plymouth", "Kingston", "South Carver",
"Plympton", "Randolph", "Rockland", "South Easton",
"West Bridgewater", "Whitman", "Lexington",
"Lexington", "Brookline", "Brookline", "Waltham",
"Waltham", "Waltham", "Babson Park", "Newton",
"Newton Center", "Newtonville",
"Newton Highlands", "Newton Lower Falls",
"Newton Upper Falls", "West Newton", "Auburndale",
"Chestnut Hill", "Chestnut Hill", "Chestnut Hill",
"Waban", "Watertown", "Arlington", "Arlington",
"Belmont", "Wellesley Hills", "Wellesley",
"Needham", "Weston", "Needham Heights",
"Buzzards Bay", "Buzzards Bay", "Buzzards Bay",
"Buzzards Bay", "Cataumet", "Chilmark", "East Falmouth",
"East Sandwich", "East Wareham", "Edgartown",
"Falmouth", "Buzzards Bay", "Woods Hole",
"Woods Hole", "Monument Beach", "Nantucket",
"North Falmouth", "Oak Bluffs", "Onset", "Pocasset",
"Sagamore", "Sagamore Beach", "Sandwich",
"Siasconset", "Vineyard Haven", "Wareham",
"West Tisbury", "West Wareham", "Nantucket",
"Hyannis", "Barnstable", "Brewster", "Centerville",
"Chatham", "Cotuit", "Cummaquid", "Dennis",
"Dennis Port", "East Dennis", "Eastham",
"East Orleans", "Forestdale", "Harwich",
"Harwich Port", "Hyannis Port", "Marstons Mills",
"Mashpee", "North Chatham", "North Eastham",
"North Truro", "Orleans", "Osterville", "Provincetown",
"South Chatham", "South Dennis",
"South Wellfleet", "South Yarmouth", "Truro", "Wellfleet",
"West Barnstable", "West Chatham",
"West Dennis", "West Harwich", "West Hyannisport",
"West Yarmouth", "Yarmouth Port", "Assonet",
"Attleboro", "Cuttyhunk", "Dighton", "East Freetown",
"East Taunton", "Fairhaven", "Fall River",
"Fall River", "Fall River", "Fall River",
"Somerset", "Somerset", "Marion", "Mattapoisett",
"New Bedford", "Acushnet", "New Bedford",
"New Bedford", "New Bedford", "North Dartmouth",
"South Dartmouth", "North Attleboro",
"Plainville", "Attleboro Falls", "North Dighton",
"Norton", "Raynham", "Rehoboth", "Rochester",
"Seekonk", "Swansea", "Berkley", "Taunton",
"Westport", "Westport Point"),
County = c("Hampden", "Hampshire", "Franklin",
"Hampshire", "Worcester", "Hampshire",
"Hampden", "Hampden", "Hampden", "Hampshire",
"Hampden", "Hampshire", "Hampden", "Hampden",
"Hampden", "Hampshire", "Hampshire", "Hampden",
"Berkshire", "Hampden", "Worcester", "Hampshire",
"Hampshire", "Hampden", "Hampshire",
"Hampden", "Worcester", "Hampshire", "Hampshire",
"Franklin", "Hampden", "Hampden", "Hampshire",
"Hampshire", "Franklin", "Hampden", "Hampden",
"Hampshire", "Hampshire", "Hampshire",
"Hampshire", "Worcester", "Hampden", "Hampshire",
"Hampden", "Franklin", "Hampshire", "Worcester",
"Hampshire", "Hampden", "Hampden", "Hampden",
"Hampden", "Worcester", "Hampshire",
"Worcester", "Hampshire", "Worcester", "Hampshire",
"Hampden", "Hampden", "Hampshire", "Hampden",
"Worcester", "Franklin", "Worcester", "Hampden",
"Hampshire", "Hampden", "Hampshire", "Hampden",
"Hampden", "Hampden", "Hampden", "Hampden",
"Hampden", "Hampden", "Hampden", "Hampden",
"Hampden", "Hampden", "Hampden", "Hampden",
"Berkshire", "Berkshire", "Berkshire", "Berkshire",
"Berkshire", "Berkshire", "Berkshire",
"Berkshire", "Berkshire", "Berkshire", "Berkshire",
"Berkshire", "Berkshire", "Berkshire",
"Berkshire", "Hampshire", "Berkshire", "Berkshire",
"Berkshire", "Berkshire", "Berkshire",
"Berkshire", "Berkshire", "Berkshire", "Berkshire",
"Berkshire", "Berkshire", "Berkshire",
"Berkshire", "Berkshire", "Berkshire", "Berkshire",
"Franklin", "Franklin", "Worcester", "Franklin",
"Franklin", "Franklin", "Franklin", "Franklin",
"Franklin", "Berkshire", "Franklin",
"Franklin", "Franklin", "Franklin", "Franklin",
"Franklin", "Franklin", "Franklin", "Franklin",
"Franklin", "Worcester", "Franklin", "Worcester",
"Franklin", "Franklin", "Franklin",
"Franklin", "Franklin", "Franklin", "Worcester",
"Worcester", "Middlesex", "Middlesex", "Middlesex",
"Worcester", "Middlesex", "Worcester",
"Worcester", "Worcester", "Worcester", "Middlesex",
"Worcester", "Worcester", "Worcester",
"Middlesex", "Worcester", "Middlesex", "Middlesex",
"Worcester", "Worcester", "Middlesex",
"Worcester", "Middlesex", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester", "Worcester",
"Hampden", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Worcester",
"Worcester", "Worcester", "Middlesex", "Middlesex",
"Middlesex", "Middlesex", "Middlesex",
"Middlesex", "Middlesex", "Middlesex", "Worcester",
"Middlesex", "Middlesex", "Worcester",
"Middlesex", "Worcester", "Middlesex", "Middlesex",
"Middlesex", "Middlesex", "Worcester",
"Worcester", "Middlesex", "Middlesex", "Worcester",
"Middlesex", "Middlesex", "Middlesex",
"Middlesex", "Middlesex", "Middlesex", "Essex",
"Middlesex", "Middlesex", "Middlesex", "Middlesex",
"Essex", "Essex", "Essex", "Essex", "Essex",
"Essex", "Essex", "Essex", "Essex", "Essex",
"Middlesex", "Middlesex", "Middlesex", "Middlesex",
"Essex", "Middlesex", "Middlesex",
"Middlesex", "Middlesex", "Middlesex", "Middlesex",
"Middlesex", "Middlesex", "Middlesex",
"Middlesex", "Essex", "Essex", "Essex", "Essex", "Essex",
"Essex", "Essex", "Essex", "Essex", "Essex",
"Essex", "Essex", "Essex", "Essex", "Essex",
"Essex", "Essex", "Middlesex", "Essex",
"Essex", "Essex", "Essex", "Essex", "Essex", "Essex",
"Essex", "Essex", "Essex", "Essex", "Essex",
"Essex", "Essex", "Norfolk", "Norfolk",
"Norfolk", "Norfolk", "Norfolk", "Norfolk",
"Norfolk", "Norfolk", "Plymouth", "Plymouth",
"Plymouth", "Bristol", "Plymouth", "Norfolk",
"Norfolk", "Norfolk", "Norfolk", "Plymouth",
"Norfolk", "Plymouth", "Norfolk", "Norfolk", "Norfolk",
"Norfolk", "Norfolk", "Norfolk", "Suffolk",
"Suffolk", "Suffolk", "Suffolk", "Suffolk",
"Suffolk", "Suffolk", "Suffolk", "Suffolk",
"Suffolk", "Suffolk", "Suffolk", "Suffolk",
"Suffolk", "Suffolk", "Suffolk", "Suffolk",
"Suffolk", "Suffolk", "Suffolk", "Suffolk", "Suffolk",
"Suffolk", "Suffolk", "Suffolk", "Middlesex",
"Middlesex", "Middlesex", "Middlesex",
"Middlesex", "Middlesex", "Middlesex", "Middlesex",
"Middlesex", "Middlesex", "Suffolk", "Suffolk",
"Suffolk", "Suffolk", "Middlesex", "Suffolk",
"Norfolk", "Norfolk", "Norfolk", "Middlesex",
"Middlesex", "Norfolk", "Norfolk", "Norfolk",
"Norfolk", "Norfolk", "Norfolk", "Suffolk",
"Suffolk", "Suffolk", "Norfolk", "Suffolk",
"Plymouth", "Plymouth", "Norfolk", "Plymouth",
"Plymouth", "Plymouth", "Plymouth", "Plymouth",
"Plymouth", "Plymouth", "Norfolk", "Plymouth",
"Plymouth", "Plymouth", "Bristol", "Bristol",
"Plymouth", "Plymouth", "Plymouth",
"Plymouth", "Plymouth", "Norfolk", "Plymouth",
"Bristol", "Plymouth", "Plymouth", "Middlesex",
"Middlesex", "Norfolk", "Norfolk", "Middlesex",
"Middlesex", "Middlesex", "Norfolk", "Middlesex",
"Middlesex", "Middlesex", "Middlesex",
"Middlesex", "Middlesex", "Middlesex", "Middlesex",
"Middlesex", "Norfolk", "Suffolk", "Middlesex",
"Middlesex", "Middlesex", "Middlesex",
"Middlesex", "Norfolk", "Norfolk", "Norfolk",
"Middlesex", "Norfolk", "Barnstable", "Plymouth",
"Plymouth", "Barnstable", "Barnstable", "Dukes",
"Barnstable", "Barnstable", "Plymouth",
"Dukes", "Barnstable", "Barnstable", "Barnstable",
"Dukes", "Barnstable", "Nantucket",
"Barnstable", "Dukes", "Plymouth", "Barnstable",
"Barnstable", "Barnstable", "Barnstable",
"Nantucket", "Dukes", "Plymouth", "Dukes", "Plymouth",
"Nantucket", "Barnstable", "Barnstable",
"Barnstable", "Barnstable", "Barnstable",
"Barnstable", "Barnstable", "Barnstable", "Barnstable",
"Barnstable", "Barnstable", "Barnstable",
"Barnstable", "Barnstable", "Barnstable",
"Barnstable", "Barnstable", "Barnstable", "Barnstable",
"Barnstable", "Barnstable", "Barnstable",
"Barnstable", "Barnstable", "Barnstable",
"Barnstable", "Barnstable", "Barnstable",
"Barnstable", "Barnstable", "Barnstable", "Barnstable",
"Barnstable", "Barnstable", "Barnstable",
"Barnstable", "Barnstable", "Bristol", "Bristol",
"Dukes", "Bristol", "Bristol", "Bristol",
"Bristol", "Bristol", "Bristol", "Bristol",
"Bristol", "Bristol", "Bristol", "Plymouth",
"Plymouth", "Bristol", "Bristol", "Bristol",
"Bristol", "Bristol", "Bristol", "Bristol", "Bristol",
"Norfolk", "Bristol", "Bristol", "Bristol",
"Bristol", "Bristol", "Plymouth", "Bristol",
"Bristol", "Bristol", "Bristol", "Bristol",
"Bristol"),
MedianHouseholdIncome = c(57694L, 52379L, 52379L, 2499L, 70325L, 86165L,
62750L, 59440L, 86523L, 75263L, 75263L,
70114L, 39868L, 58780L, 43349L, 51442L, 63699L,
85221L, 50750L, 71716L, 41875L, 78011L, 89965L,
87045L, 58953L, 81304L, 92750L, 67096L,
80000L, 80000L, 37954L, 68869L, 68869L, 62222L,
87174L, 67715L, 78986L, 57485L, 73438L, NA, NA,
85938L, 59211L, 57000L, 67132L, 72000L, 89423L,
61603L, 66681L, 76737L, 27105L, 49844L,
50465L, 51768L, 51768L, 51768L, 51768L, 65547L,
90625L, 62423L, NA, 51406L, 51735L, 75799L,
103750L, 21250L, 104128L, 77083L, NA, 76563L,
16720L, 30053L, 17569L, 111231L, 26772L, 38499L,
35191L, 61112L, 47439L, 65977L, 63895L, 40360L,
NA, 47614L, 49777L, 74583L, 77857L, 38446L,
61512L, 61063L, 29000L, 65214L, 63000L, 57014L,
84615L, 67708L, 68948L, 81172L, 71979L, 55556L,
69821L, 40928L, 74554L, 92083L, 68636L,
55375L, 59500L, 57917L, 62727L, 112756L, 36042L,
80000L, 74107L, 78068L, 80000L, 48477L, 74167L,
53733L, 66085L, 57750L, 55313L, 53125L,
101023L, 106146L, 85781L, 70109L, 60208L, 52647L,
61630L, 31458L, 82548L, 69226L, 70313L, 69028L,
43413L, 65529L, 55469L, 72813L, 54036L,
74022L, 54886L, 43750L, 57885L, 43500L, 51412L,
85064L, 95833L, 79750L, 50547L, 50547L, 50547L,
50547L, 60156L, 74142L, 48915L, 123918L,
143625L, 93387L, 57610L, 119177L, 97775L, 90029L,
67541L, 98036L, 64872L, 84489L, 100071L, 84851L,
64539L, 74576L, 97417L, 80260L, 97074L,
64219L, 93921L, 68362L, 80234L, 94531L, 58438L,
106250L, 99674L, 78348L, 104508L, 104630L, 64135L,
NA, 74713L, 90500L, 84432L, 111875L, 89348L,
73133L, 105283L, 74883L, 68865L, 128006L,
100000L, 100962L, 101229L, 50202L, 85390L, NA,
65386L, 102500L, 95800L, 119115L, 94809L, 52107L,
64281L, 107604L, 73463L, 66317L, 66607L,
101315L, 64808L, 42259L, 50487L, 37703L, 65135L,
43500L, 20578L, 42903L, 31003L, 81830L, 95595L,
105940L, 52746L, 160750L, 101077L, 133075L,
120309L, 125208L, 93276L, 151618L, 170703L,
137547L, 123992L, 118933L, 101761L, 151357L,
83765L, 75418L, 95833L, 125816L, 75976L, 106332L,
170872L, 143375L, 153500L, 144766L, 170945L,
166548L, 84857L, 99254L, 143292L, 99881L,
115533L, 86644L, 138700L, 61375L, 64238L, 113417L,
95031L, 77697L, 20596L, 38199L, 46629L,
73525L, 105661L, 46102L, 52008L, 50911L, 40982L,
84417L, 93494L, 77055L, 124750L, 113553L, 94817L,
101620L, 93337L, 138006L, 118549L, 152196L,
22057L, 42851L, 88395L, 57638L, 82188L,
105029L, 81384L, 78638L, 77893L, 155034L, 87986L,
79795L, 109327L, 65348L, NA, 80829L, 113509L,
113509L, 105500L, 110025L, 107727L, 89887L,
90662L, 72900L, 65060L, 72015L, 89338L, 65476L,
112250L, 131387L, 96979L, 135882L, 95533L,
96583L, 140000L, 89451L, 204018L, 120250L, 98199L,
111935L, 125144L, 80584L, 26953L, 111141L,
92610L, 153847L, 115432L, 100230L, 139137L,
128563L, 87516L, 114766L, 133229L, 115333L, 78343L,
105420L, 146042L, 107444L, 126224L, 129716L,
108438L, 39329L, 91212L, 89452L, 38759L,
103422L, 70575L, 30663L, 32243L, 27964L, 56024L,
50227L, 53382L, 50039L, 91597L, 52154L, 103834L,
84847L, 72127L, 93343L, 49938L, 61566L,
64877L, 87671L, 91250L, 91596L, 77261L, 120729L,
90285L, 102033L, 68553L, 62283L, 57143L, 57143L,
51875L, 53771L, 69928L, 86459L, 64000L,
67028L, 82159L, 78839L, 93434L, 90320L, 88993L,
126000L, 81040L, 58674L, 85053L, 73948L, 82238L,
NA, 170152L, 43403L, 43403L, 47724L, 63718L,
69709L, 88640L, 73904L, 123613L, 86568L, 77993L,
111311L, 96389L, 67589L, 79811L, 97990L,
91643L, 113783L, NA, 101447L, 83746L, 89796L, NA,
87438L, 70163L, 77573L, 94457L, 85368L,
79705L, 168065L, 158554L, 111642L, 102342L, 94886L,
87055L, 73042L, NA, 103978L, 169963L, 118148L,
159517L, 104375L, 102946L, 137438L, 115345L,
119964L, 119964L, 119964L, 212394L, 92959L,
104583L, 101713L, 118342L, 187819L, 160644L,
147375L, 196651L, 126866L, 75502L, 75502L,
75502L, 75502L, 88844L, 79792L, 67880L, 95966L,
67993L, 75404L, 70758L, 48750L, 92188L, 92188L,
NA, 92327L, 83659L, 66091L, 33679L, 71741L, NA,
86310L, 84087L, NA, 48869L, 59449L, 92188L,
84497L, NA, 46821L, 106299L, 69606L, 80072L,
76793L, 62021L, 142692L, 70850L, 44787L, NA,
62143L, NA, 92286L, 78077L, 62933L, NA, 82406L,
73841L, 77991L, NA, 60250L, 61506L, 75000L,
47500L, 57540L, 54924L, 61875L, 56242L, 63306L,
57667L, 94250L, 89737L, 63675L, 60000L, NA,
70736L, 68638L, 94773L, 70136L, NA, 98112L,
81123L, 93034L, 62090L, 47992L, 33383L, 37617L,
37932L, 70183L, 75154L, 76576L, 85870L, 37784L,
69402L, 33125L, 56277L, 32554L, 75891L, 70828L,
85864L, 93889L, 106118L, 82130L, 102869L,
93125L, 96098L, 102227L, 86014L, 81469L, 89597L,
53201L, 80569L, 74009L),
MedianMonthlyHousingCost = c(1141L, 1349L, 1349L, 1215L, 1265L, 1338L,
1296L, 1102L, 1262L, 1066L, 1066L, 1115L,
912L, 985L, 902L, 984L, 1089L, 1397L, 738L,
1182L, 858L, 1106L, 1177L, 1252L, 1067L, 1302L,
1000L, 1203L, 1157L, 1157L, 892L, 1096L, 1096L,
1341L, 1478L, 1143L, 1139L, 1169L, 1131L, NA,
NA, 1301L, 1013L, 1052L, 1084L, 1527L, 1493L,
1083L, 1093L, 1327L, 682L, 964L, 1053L, 1111L,
1111L, 1111L, 1111L, 1104L, 1556L, 1084L, NA,
902L, 942L, 921L, 1458L, 571L, 1531L, 1251L,
NA, 1236L, 828L, 931L, 725L, 1793L, 834L,
1017L, 985L, 1150L, 1047L, 1189L, 1203L, 963L, NA,
931L, 838L, 1093L, 1124L, 721L, 938L, 1127L,
963L, 1082L, 1031L, 1195L, 1214L, 1066L, 988L,
1068L, 1216L, 1200L, 1244L, 806L, 925L,
1306L, 1204L, 985L, 1057L, 1147L, 1419L, 846L,
981L, 829L, 1237L, 1186L, 1432L, 968L, 1201L,
972L, 1228L, 539L, 928L, 939L, 1368L, 1516L, 445L,
1138L, 1191L, 760L, 1052L, 755L, 1073L,
1082L, 1153L, 1108L, 910L, 1071L, 752L, 1096L,
925L, 1329L, 1272L, 918L, 881L, 924L, 1112L,
1524L, 1350L, 1190L, 985L, 985L, 985L, 985L, 968L,
NA, 868L, 2020L, 2276L, 1488L, 1042L, 1911L,
1643L, 1499L, 1522L, NA, 1077L, 1497L, 1448L,
1679L, 1153L, 1271L, 1770L, 1425L, 1605L, 980L,
1484L, 1271L, 1215L, 1505L, 1302L, 1757L,
1693L, 1270L, 1613L, 1658L, 1163L, 1017L, 1313L,
1472L, 1299L, 1963L, 1606L, 1145L, 1710L,
1072L, 1247L, 1909L, 1254L, 1702L, 1523L, 951L,
1364L, 816L, 1137L, 1616L, 1660L, 1902L, 1480L,
999L, 1137L, 1880L, 1324L, 1206L, 1164L,
1803L, 1259L, 1084L, 1170L, 1002L, 1228L, 1053L,
780L, 1105L, 1021L, 1122L, 1623L, 1717L, 1355L,
2242L, 1221L, 2038L, 2000L, 2228L, 2610L,
2495L, 2837L, 2459L, 2169L, 1998L, 1281L, 2385L,
1415L, 1453L, 1585L, 1984L, 1366L, 1770L,
3108L, 2232L, 2122L, 2024L, 2789L, 2533L, 1530L,
1865L, 2104L, 1721L, 1817L, 1500L, 2129L, 1324L,
1278L, 1953L, 1610L, 1372L, 911L, 1124L,
1196L, 1389L, 1840L, 1207L, 1211L, 1165L, 1131L,
1584L, 1623L, 1459L, 1856L, 1827L, 1810L,
1505L, 1701L, 2128L, 2003L, 2513L, 848L, 1208L,
1711L, 1274L, 1560L, 2040L, 1597L, 1562L, 1441L,
2690L, 1716L, 1565L, 2119L, 1319L, NA, 1440L,
2099L, 2099L, 2113L, 1862L, 1955L, 1641L,
1892L, 1429L, 1400L, 1435L, 1867L, 1328L, 2066L,
2199L, 1903L, 2075L, 1672L, 1859L, 2694L,
1811L, 2858L, 2285L, 1668L, 1858L, 2424L, 1530L,
939L, 1677L, 1750L, 2562L, 2124L, 1684L, 2277L,
2452L, 1512L, 2019L, 2185L, 2516L, 1564L,
2030L, 2329L, 1750L, 2397L, 2688L, 2463L, 1769L,
1846L, 2176L, 1608L, 2001L, 1910L, 1064L,
1155L, 995L, 1480L, 1493L, 1429L, 1432L, 1777L,
1326L, 1794L, 1698L, 1551L, 1636L, 1621L, 1635L,
1416L, 2024L, 1905L, 1610L, 1812L, 3044L,
1753L, 1891L, 1573L, 1470L, 1418L, 1418L, 1376L,
1422L, 1447L, 1667L, 2380L, 1494L, 1384L,
1597L, 1603L, 1599L, 1621L, 2251L, 1503L, 1341L,
1555L, 1638L, 2861L, NA, 3076L, 1788L, 1788L,
1212L, 1400L, 1579L, 1515L, 1566L, 2424L, 1761L,
1499L, 1950L, 1662L, 1556L, 1463L, 1587L,
1534L, 1861L, NA, 1824L, 1638L, 1784L, NA, 1924L,
1605L, 1462L, 1700L, 1522L, 1499L, 2735L,
2573L, 2248L, 2163L, 1802L, 1711L, 1563L, NA,
2029L, 2644L, 2018L, 2337L, 2361L, 2037L, 2266L,
1869L, 2135L, 2135L, 2135L, 2905L, 1802L,
1772L, 1704L, 2061L, 3181L, 2434L, 2249L, 3152L,
2447L, 1421L, 1421L, 1421L, 1421L, 1444L,
1541L, 1298L, 1852L, 1269L, 1587L, 1109L, 1203L,
1258L, 1258L, NA, 1917L, 1376L, 1695L, 1114L,
1295L, 1862L, 1910L, 1794L, 1716L, 1569L, 1265L,
1741L, 1064L, NA, 1191L, 1716L, 1293L, 1432L,
1208L, 1639L, 1019L, 952L, 1165L, 1195L,
1015L, NA, 1611L, 1480L, 1074L, 3606L, 1440L,
1494L, 1375L, NA, 1184L, 1132L, 1459L, 1251L,
1164L, 1044L, 966L, 1274L, 991L, 931L, 1522L,
1542L, 1139L, 899L, 1664L, 1297L, 1379L, 1769L,
1348L, NA, 1766L, 1339L, 1233L, 1177L, 903L,
798L, 765L, 738L, 974L, 1250L, 1588L, 1633L,
873L, 1144L, 789L, 899L, 807L, 1429L, 1236L,
1383L, 1601L, 1612L, 1694L, 1671L, 1711L, 1779L,
1657L, 1482L, 1333L, 1404L, 1130L, 1328L,
1327L),
Population = c(17537L, 30280L, 30280L, 11131L, 5014L, 14906L,
1272L, 384L, 3724L, 1507L, 1507L, 531L,
23026L, 30148L, 2604L, 958L, 17870L, 16156L, 728L,
11211L, 1151L, 551L, 6300L, 2313L, 5301L,
5193L, 772L, 2897L, 1129L, 1129L, 40362L, 2334L,
2334L, 1658L, 1997L, 21331L, 8801L, 15729L,
10587L, 574L, 9L, 1849L, 8919L, 637L, 1206L,
1490L, 6090L, 477L, 17755L, 9711L, 480L, 2532L,
1827L, 10637L, 10637L, 10637L, 10637L, 3182L,
183L, 41652L, 683L, 399L, 28671L, 1133L, 348L,
327L, 14659L, 2607L, 54L, 1186L, 2409L,
23635L, 11601L, 16048L, 11304L, 28925L, 30125L,
14774L, 13236L, 2798L, 6750L, 8884L, 0L, 44775L,
8211L, 818L, 2351L, 209L, 3169L, 6839L, 86L,
8359L, 2671L, 1197L, 2662L, 5917L, 4493L, 475L,
333L, 108L, 803L, 15703L, 742L, 977L, 859L,
764L, 2138L, 357L, 506L, 447L, 1110L, 205L,
1360L, 7853L, 813L, 17715L, 1468L, 13281L, 2626L,
170L, 1472L, 1642L, 1743L, 1759L, 46L, 1518L,
464L, 126L, 1231L, 86L, 2209L, 1604L, 917L,
3012L, 7819L, 1218L, 605L, 1316L, 4032L, 4160L,
3662L, 5096L, 744L, 836L, 40666L, 6210L,
3195L, 7703L, 1712L, 1712L, 1712L, 1712L, 3460L,
563L, 20496L, 11282L, 4630L, 4581L, 41446L,
9754L, 11150L, 12049L, 7572L, 511L, 4124L, 7454L,
7566L, 1964L, 10738L, 16412L, 3098L, 9201L,
4524L, 3406L, 13379L, 13855L, 2123L, 8745L,
3490L, 6657L, 15061L, 2510L, 3497L, 7735L, 6702L,
227L, 13521L, 3237L, 1247L, 14918L, 6262L,
4760L, 7709L, 2337L, 11386L, 3438L, 2299L, 8463L,
36269L, 16858L, 4477L, 243L, 11856L, 8000L,
6006L, 7706L, 13864L, 16926L, 11637L, 18836L,
7639L, 4661L, 9864L, 9297L, 24166L, 19981L,
36772L, 28742L, 19375L, 8698L, 3371L, 20714L,
23438L, 2451L, 4845L, 32098L, 39226L, 716L,
5546L, 22680L, 17478L, 14031L, 2012L, 5167L, 5160L,
19383L, 501L, 14480L, 5955L, 16720L, 19843L,
39771L, 10560L, 5995L, 28694L, 35715L, 4302L,
9520L, 4791L, 7061L, 18697L, 13850L, 40375L,
26103L, 35375L, 32348L, 25961L, 30948L, 3337L,
26524L, 23372L, 8569L, 6697L, 13047L, 5248L,
48295L, 25942L, 49587L, 30170L, 16890L, 29849L,
34756L, 29561L, 6752L, 10676L, 9106L, 15598L,
24894L, 30433L, 12305L, 26450L, 24087L,
23538L, 22579L, 1878L, 48218L, 17320L, 25590L,
28037L, 14758L, 3488L, 17218L, 41431L, 8228L,
2812L, 27391L, 3687L, 29858L, 136L, 13810L,
13425L, 13425L, 5327L, 20393L, 9656L, 17890L, 4152L,
9035L, 52313L, 7184L, 6232L, 42991L, 7991L,
6496L, 5179L, 4545L, 16929L, 22829L, 8393L,
25362L, 5922L, 4410L, 17448L, 32843L, 23047L,
10402L, 65L, 23678L, 26032L, 12610L, 13162L,
8144L, 11388L, 10897L, 29121L, 18042L, 18148L,
1572L, 28338L, 19358L, 15612L, 11597L, 4211L,
4051L, 2270L, 7452L, 7464L, 13247L, 29244L,
23215L, 27325L, 28152L, 15719L, 28479L, 24643L,
55074L, 35254L, 29141L, 37257L, 46655L, 18901L,
39435L, 32819L, 28505L, 18057L, 42644L, 33084L,
37668L, 36979L, 19737L, 13664L, 2929L,
26773L, 24682L, 26430L, 61375L, 44993L, 44993L,
39263L, 53873L, 18391L, 59779L, 2569L, 56541L,
19434L, 17849L, 28132L, 21967L, 37082L, 27527L,
15301L, 15146L, 17415L, 8028L, 1177L, 27L,
2609L, 25023L, 25023L, 61320L, 33841L, 4468L,
27434L, 11617L, 15572L, 14301L, 7739L, 14328L,
10560L, 10753L, 24166L, 11292L, 16275L, 12885L,
1178L, 18230L, 58500L, 13210L, 195L, 2912L,
33980L, 17849L, 9938L, 7117L, 14864L, 14579L,
18760L, 20774L, 30113L, 18646L, 15470L, 28696L,
1680L, 12465L, 19473L, 9911L, 7214L, 1520L,
3155L, 12112L, 8568L, 22105L, 22105L, 22105L,
5568L, 34715L, 28028L, 16964L, 25940L, 16309L,
11015L, 20128L, 12027L, 10301L, 13337L, 13337L,
13337L, 13337L, 815L, 1757L, 19191L, 6572L,
3571L, 4292L, 8294L, 881L, 909L, 909L, 35L,
10590L, 2869L, 4675L, 749L, 4028L, 325L, 3008L,
9501L, 312L, 4100L, 10940L, 2417L, 4873L, 10L,
15063L, 2277L, 9736L, 9923L, 4055L, 3301L,
141L, 3011L, 2949L, 191L, 4908L, 0L, 4393L, 9516L,
1806L, 121L, 6589L, 14054L, 906L, 0L, 942L,
5905L, 3257L, 2952L, 1030L, 6657L, 96L, 9226L,
638L, 3075L, 2807L, 158L, 1158L, 889L, 368L,
8397L, 6314L, 4472L, 44326L, 25L, 3703L, 4703L,
6295L, 16027L, 31126L, 25985L, 14236L,
17391L, 2453L, 15804L, 5065L, 6245L, 43686L, 10443L,
11184L, 24294L, 15637L, 23568L, 11316L,
27100L, 9000L, 1933L, 3872L, 19515L, 14018L,
11990L, 5199L, 14957L, 16204L, 6630L, 50358L,
15832L, 279L)
)
```
# Find highest and lowest median incomes. Ignores ties for code simplicity.
```{r}
zip_highest_income_row <- filter(markdowndata, MedianHouseholdIncome == max(MedianHouseholdIncome, na.rm = TRUE))
zip_lowest_income_row <- filter(markdowndata, MedianHouseholdIncome == min(MedianHouseholdIncome, na.rm = TRUE))
```
```
Zip code `r zip_highest_income_row$ZipCode[1]` in `r zip_highest_income_row$City[1]` has the highest median income in Massachusetts, `r scales::dollar(zip_highest_income_row$MedianHouseholdIncome[1])`.
Zip code `r zip_lowest_income_row$ZipCode[1]` in `r zip_lowest_income_row$City[1]` has the lowest median income in Massachusetts, `r scales::dollar(zip_lowest_income_row$MedianHouseholdIncome[1])`.
#### Distribution of median household incomes
```{r histo, fig.width = 4, fig.height = 2, warning=FALSE, message=FALSE}
ggplot(markdowndata, aes(x = MedianHouseholdIncome)) +
geom_histogram(binwidth = 10000, color = "black", fill = "darkgreen") +
theme_classic() +
xlab("") + ylab("") +
scale_x_continuous(labels = dollar)
```
#### Income, Housing Costs, and Population
```{r table}
DT::datatable(markdowndata, filter = 'top') %>%
formatCurrency(4:5, digits = 0) %>%
formatCurrency(6, currency = "", digits = 0)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.