Plotting Florida

florida

florida

Ploting Florida

Today, I learned some “Spatial Analysis” R packages (e.g., ggmap, tigris) from the last workshop of 8-week-long workshop series — R for the Social Sciences Weekly Workshops. It was a really great workshop! I leared a lot of R and Stats (e.g., Linear Models, Generalized Linear Models, autocorrelation, etc), even though the topics were more focused on Social Sciences.

Thanks to Raffaele Vacca, Tom Smith, and Till Krenz!

Here are some quick and simple code to plot Florida:

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.4.4
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.4.2
## ── Attaching packages ────────────────────────── tidyverse 1.2.1 ──
## ✔ tibble  1.4.2     ✔ purrr   0.2.4
## ✔ tidyr   0.8.0     ✔ dplyr   0.7.7
## ✔ readr   1.1.1     ✔ stringr 1.3.1
## ✔ tibble  1.4.2     ✔ forcats 0.2.0
## Warning: package 'tidyr' was built under R version 3.4.3
## Warning: package 'purrr' was built under R version 3.4.2
## Warning: package 'dplyr' was built under R version 3.4.4
## Warning: package 'stringr' was built under R version 3.4.4
## ── Conflicts ───────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()

# Get the shape data for the state of Florida and We need more detailed shape data to show county borders
flr <- map_data("county") %>% 
  filter(region == "florida")
## 
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
## 
##     map
## Warning: package 'bindrcpp' was built under R version 3.4.4

# Create a ggplot object that we can add layers to.
flr_plot <- 
  ggplot(data = flr, mapping = aes(x = long, y = lat)) + 
  geom_map(map = flr, color = "orange", fill = "blue",
           aes(map_id=region)) + 
  coord_quickmap()

flr_plot


#of course, we can do more stuff, like adding county names...
Avatar
Miao Sun
Postdoc Fellow
comments powered by Disqus