[R] Choropleth map over an outline of Florida's 67 counties

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Fri May 31 05:10:49 CEST 2019


Since Googling "chloropleth ggplot" yields many possibilities (e.g.[1]), I can't say I am very motivated to read them and guess what deficiencies you found that made them miss your target. 

Also note that had you read the Posting Guide you would know that there is a mailing list dedicated to spatial analysis with R... r-sig-geo.

[1] https://unconj.ca/blog/choropleth-maps-with-r-and-ggplot2.html

On May 30, 2019 11:42:59 AM PDT, Thomas MacFarland <tommac using nova.edu> wrote:
>Everyone:
>
>I am trying to build a choropleth map that uses colored shading to
>identify the number of incidents for a specific event during Calendar
>Year 2018 throughout Florida, ideally on a county-by-county basis.
>
>I'd also like to include the county borders in the map, to emphasize
>urban v rural.  However, if the county borders cannot be displayed
>along with the choropleth colored shading that would be acceptable.
>
>Everything is fine up to the choropleth map part of this activity and
>that is where I'm stuck.  Any idea, pointers, recommended references,
>etc. would be helpful.  Somehow, I need to have the dataset with number
>of incidents interface with the mapping part of this activity and I've
>run out of online resources for review - but still no success.
>
>Thanks and I'm very grateful for any assistance.
>
>Best wishes.
>
>Tom
>
>#############################################################
># < CY2018Incidents67FloridaCounties >
>#
># There are two main goals for this activity:
>#
># Produce a map of Florida that outlines all 67 counties,
># which will serve as a base map of Florida.
>#
># Place over the base map of Florida a choropleth map that
># uses colored shading to give a sense of the number of
># incidents, by county, during Calendar Year 2018.
>#
># Ideally, the county outlines will show along with the
># colored shading.
>#
># As expected, the highly-populated urban counties will have
># more incidents than the sparsely-populated rural counties.
>
># Start out with a clean slate.
>
>ls()
>rm(list=ls(all=TRUE))
>ls()
>
># Install the required packages.
>
>install.packages(c("ggplot2", "ggthemes", "ggmap", "maps",
>  "mapdata"))
>
>library(ggplot2); library(ggthemes); library(ggmap)
>library(maps); library(mapdata); library()
>
>
># Build a dataframe of U.S. states and a dataframe of
># Florida.
>
>States.df <- map_data("state")
>str(States.df)
>head(States.df)
>Florida.df <- subset(States.df, region == "florida")
>str(Florida.df)
>head(Florida.df)
>
># Build a dataframe of U.S. counties and a dataframe of
># Florida counties.
>
>Counties.df <- map_data("county")
>str(Counties.df)
>head(Counties.df)
>FloridaCounties.df <- subset(Counties.df, region == "florida")
>str(FloridaCounties.df)
>head(FloridaCounties.df)
>
># Produce a map that outlines all 67 counties in Florida.
>
>Florida_map1 <- ggplot2::ggplot(data = FloridaCounties.df,
>  mapping = aes(x = long, y = lat, group = group)) +
>  coord_fixed(1.3) +
>  geom_polygon(color = "red", fill = "aliceblue")
>
>par(ask=TRUE); Florida_map1
>  # Map of Florida with all 67 counties in a red outline
>
># Build a dataframe that details the number of Calendar Year
># 2018 incidents for each county.
>
>CY2018Incidents.df <- read.table(textConnection("
>FIPSCode   Incidents         # County
>12001      89                # Alachua
>12003      1                 # Baker
>12005      21                # Bay
>12007      4                 # Bradford
>12009      165               # Brevard
>12011      8218              # Broward
>12013      1                 # Calhoun
>12015      35                # Charlotte
>12017      16                # Citrus
>12019      42                # Clay
>12021      115               # Collier
>12023      10                # Columbia
>12027      7                 # De Soto
>12029      0                 # Dixie
>12031      368               # Duval
>12033      21                # Escambia
>12035      29                # Flagler
>12037      2                 # Franklin
>12039      9                 # Gadsden
>12041      0                 # Gilchrist
>12043      2                 # Glades
>12045      0                 # Gulf
>12047      0                 # Hamilton
>12049      3                 # Hardee
>12051      15                # Hendry
>12053      24                # Hernando
>12055      16                # Highlands
>12057      613               # Hillsborough
>12059      0                 # Holmes
>12061      48                # Indian River
>12063      2                 # Jackson
>12065      0                 # Jefferson
>12067      0                 # Lafayette
>12069      80                # Lake
>12071      391               # Lee
>12073      62                # Leon
>12075      3                 # Levy
>12077      0                 # Liberty
>12079      2                 # Madison
>12081      72                # Manatee
>12083      63                # Marion
>12085      70                # Martin
>12086      4075              # Miami-Dade
>12087      18                # Monroe
>12089      12                # Nassau
>12091      25                # Okaloosa
>12093      5                 # Okeechobee
>12095      547               # Orange
>12097      93                # Osceola
>12099      1602              # Palm Beach
>12101      115               # Pasco
>12103      232               # Pinellas
>12105      154               # Polk
>12107      10                # Putnam
>12113      14                # Santa Rosa
>12115      61                # Sarasota
>12117      183               # Seminole
>12109      60                # St. Johns
>12111      170               # St. Lucie
>12119      1                 # Sumter
>12121      2                 # Suwannee
>12123      1                 # Taylor
>12125      0                 # Union
>12127      137               # Volusia
>12129      1                 # Wakulla
>12131      5                 # Walton
>12133      2"), header=TRUE) # Washington
>
>attach(CY2018Incidents.df)
>str(CY2018Incidents.df)
>head(CY2018Incidents.df)
>
># And here is where I am stuck!  How do I produce what would
># otherwise be Florida_map2, where the choropleth map of
># incidents is placed over the map that outlines Florida's 67
># counties.
>
># May 30, 2019 02:25 PM
>
>#############################################################
>
>----------
>Thomas W. MacFarland, Ed.D.
>Senior Research Associate; Institutional Effectiveness and Associate
>Professor
>Nova Southeastern University
>Voice 954-262-5395 tommac using nova.edu<mailto:tommac using nova.edu>
>
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list