Before we get started, let’s create our file structure so that we can all work together:
Download this dataset.
Save it in the location on your computer where you want to work for the entirety of this workshop.
Create a
New Project
- in an
Existing Directory
- the map_workshop folder
Spatial data (also called geospatial data)
The building block of vector data is the coordinate point. Just like in a scatter plot, each coordinate is a combination of an x and y value. With spatial data, x and y represent locations on the earth.
## create dataframe to show points
example = data.frame(long=c(41.3, 41.8, 42.9),
lat=c(-116.8, -116, -115.3))
poly_example = data.frame(x=c(41.3, 41.7, 42.9, 42.9, 41.3, 41.3),
y=c(-116.8, -116.8, -116, -115.3, -115.3, -116.8))
plot(example, col="blue", type = "p", pch = 16)
plot(example, type="l", col="green", lwd=5)
plot(poly_example, type="l", col="red", lwd=5)Longtidue and Latitude
x = longitude
y = latitude
The confusing world of coordinates
The combination of latitude and longitude is usually called a coordinate, and can be represented as
In R, we use the ‘longitude, latitude’ order
The building block of raster data is the grid.
You can create a map of sorts with any point data that has latitude and longitude coordinates (or any x,y coordinates that refere to a location on earth).
Create a new script, called georgia_title_1_schools.R
Load the tidyverse at the top of the script
Read in a csv of schools in Georgia with latitude and longitude columns
| school | long | lat | total_enroll |
|---|---|---|---|
| 7 PILLARS CAREER ACADEMY | -84.37143 | 33.63869 | 96 |
| A.L. BURRUSS ELEMENTARY SCHOOL | -84.57810 | 33.94340 | 406 |
| AARON COHN MIDDLE SCHOOL | -84.82468 | 32.55014 | 498 |
| AARON COHN REGIONAL YOUTH DETENTION CENTER | -84.85224 | 32.52715 | 17 |
| ABBOTTS HILL ELEMENTARY SCHOOL | -84.19640 | 34.05620 | 574 |
Plot the schools as a regular ggplot scatterplot – with Longitude on the x-axis and Latitude on the y-axis
You might even begin to recognize the shape of Georgia:
The shape is distorted because latitude and longitude represent points on a globe
Time to talk about projections…