Skip to content

Commit 6445672

Browse files
committed
update xy plotting
- add URL for data ingest - two methods of plotting: - xy - transform to sf
1 parent 2d91b6d commit 6445672

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

01_georeference.Rmd

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ library(mapview)
2323
2012 Starbucks locations ([data source](https://github.com/libjohn/mapping-with-R/blob/master/data/All_Starbucks_Locations_in_the_US_-_Map.csv))
2424

2525
```{r load-data, message=FALSE, warning=FALSE}
26-
starbucks <- read_csv("data/All_Starbucks_Locations_in_the_US_-_Map.csv")
26+
starbucks <- read_csv("https://raw.githubusercontent.com/libjohn/mapping-with-R/master/data/All_Starbucks_Locations_in_the_US_-_Map.csv")
2727
```
2828

2929
### Subset Data to North Carolina
@@ -34,21 +34,29 @@ starbucksNC <- starbucks %>%
3434
starbucksNC
3535
```
3636

37-
## Transform to Spatial Data
37+
## Make the Map
3838

39-
Transform our standard tibble (i.e. the starbucksNC data frame) into a spacial data frame via the simple features function, `st_as_sf()`. Here we set the [map projection](https://en.wikipedia.org/wiki/Map_projection) to a common standard, WGS84, via the argument `crs = 4326`.)
39+
In this example, plot latitude (y coordinates) and longitude (x coordinates), then set the map projection to a common projection standard, WGS84, via the argument `crs = 4326`.)
40+
41+
```{r map1}
42+
mapview(starbucksNC, xcol = "Longitude", ycol = "Latitude", crs = 4269, grid = FALSE)
43+
```
44+
45+
## Alternative: Transform data to Spatial object
46+
47+
Another way to plot the x & y coordinates is by transforming the starbucksNC tibble (i.e. the starbucksNC data frame) into a spacial data frame via the simple features function, `st_as_sf()`. It's important to set the [map projection](https://en.wikipedia.org/wiki/Map_projection) to a common standard, WGS84, via the argument `crs = 4326`.)
4048

4149
```{r convert2spacial}
42-
sbuxsfc <- st_as_sf(starbucksNC, coords = c("Longitude", "Latitude"), crs=4326)
50+
sbux_sf <- st_as_sf(starbucksNC, coords = c("Longitude", "Latitude"), crs=4326)
4351
```
4452

45-
## Visualize the Map
53+
### Now Map the sf object.
4654

4755
Below, you can plot the latitude and longitude coordinate, and set the `map.types` argument to `openStreetMap`. Base maps are set with `map.types`. For example a high contrast, black and white basemap can be set with the argument `map.types = "Stamen.Toner"`. See available [map types](http://leaflet-extras.github.io/leaflet-providers/preview/), or leave out the map.types argument for a set of default base maps to choose via the layering button.
4856

4957
```{r plotmap}
5058
#mapview(sbuxsfc, map.types = "Stamen.Toner")
51-
mapview(sbuxsfc)
59+
mapview(sbux_sf)
5260
```
5361

5462

0 commit comments

Comments
 (0)