Local Salem Area Maps
A Citation
I found a starting point on local maps in Seattle.
library(ggmap)
## Loading required package: ggplot2
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
library(osmdata)
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ tibble 3.0.4 ✓ dplyr 1.0.2
## ✓ tidyr 1.1.2 ✓ stringr 1.4.0
## ✓ readr 1.4.0 ✓ forcats 0.5.0
## ✓ purrr 0.3.4
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
SLE <- get_map(getbb("Salem, OR"), source="osm")
## Source : http://tile.stamen.com/terrain/12/647/1473.png
## Source : http://tile.stamen.com/terrain/12/648/1473.png
## Source : http://tile.stamen.com/terrain/12/649/1473.png
## Source : http://tile.stamen.com/terrain/12/647/1474.png
## Source : http://tile.stamen.com/terrain/12/648/1474.png
## Source : http://tile.stamen.com/terrain/12/649/1474.png
## Source : http://tile.stamen.com/terrain/12/647/1475.png
## Source : http://tile.stamen.com/terrain/12/648/1475.png
## Source : http://tile.stamen.com/terrain/12/649/1475.png
SLE %>% ggmap()
An Oregon Map of Liquor Stores
The setup for a Google Cloud account is kind of a pain and it requires a billing option. That was annoying but eventually fixed.
OR <- get_map(getbb("Oregon"), source="osm")
## Source : http://tile.stamen.com/terrain/7/19/45.png
## Source : http://tile.stamen.com/terrain/7/20/45.png
## Source : http://tile.stamen.com/terrain/7/21/45.png
## Source : http://tile.stamen.com/terrain/7/22/45.png
## Source : http://tile.stamen.com/terrain/7/19/46.png
## Source : http://tile.stamen.com/terrain/7/20/46.png
## Source : http://tile.stamen.com/terrain/7/21/46.png
## Source : http://tile.stamen.com/terrain/7/22/46.png
## Source : http://tile.stamen.com/terrain/7/19/47.png
## Source : http://tile.stamen.com/terrain/7/20/47.png
## Source : http://tile.stamen.com/terrain/7/21/47.png
## Source : http://tile.stamen.com/terrain/7/22/47.png
OR %>% ggmap()
# Get the Data on Liquor Stores from https://ryano.net/oregonliquorstores/ I copied and pasted it. It comes from a .pdf available from OLCC.
library(readr)
GeoCodeLiquorStores <- read_delim(url("https://github.com/robertwwalker/DADMStuff/raw/master/GeoCodeLiquorStores.csv"), "\t", escape_double = FALSE, trim_ws = TRUE)
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## `Store [pdx]` = col_character(),
## Address = col_character(),
## Mon = col_character(),
## Tue = col_character(),
## Wed = col_character(),
## Thu = col_character(),
## Fri = col_character(),
## Sat = col_character(),
## Sun = col_character()
## )
GeoCodeLiquorStores$GCAdd <- str_split_fixed(GeoCodeLiquorStores$Address, fixed("("), 2)[,1]
GeoCodeLiquorStores$GCPhN <- str_split_fixed(GeoCodeLiquorStores$Address, fixed("("), 2)[,2]
Now I need a new package to try and geocode this.
install.packages("RDSTK")
# GeoCode the addresses from above.
# Google will charge for this, not much but it is a pain to set up
# LatLon.LS <- geocode(GeoCodeLiquorStores$GCAdd, source = "google")
# Embedded Output in lat lon
LatLon.LS <-read.csv(url("https://github.com/robertwwalker/DADMStuff/raw/master/GeoCodedLiquor.csv"))
# Merge coordinates with the dataset of liquor stores
GCLS <- GeoCodeLiquorStores %>% mutate(lat = LatLon.LS$lat, lon=LatLon.LS$lon)
# Rename the first variable
names(GCLS)[1] <- "Store"
# Create the hover
GCLS <- GCLS %>% mutate(labelM = paste0(Store,"<br>",GCAdd,"<br>",GCPhN))
gp <- ggmap(OR) + geom_point(data=GCLS, aes(x=lon, y=lat, text=labelM), alpha=0.2, size=2, color="magenta") + ggnetwork::theme_blank() + labs("A Map of Oregon Liquor Stores")
## Warning: Ignoring unknown aesthetics: text
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggmap':
##
## wind
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
GGP <- ggplotly(gp, tooltip = "text")
htmlwidgets::saveWidget(
widgetframe::frameableWidget(GGP), here:::here('static/img/widgets/sleggpmap.html'))