By Nicole Burke, PhD
R-Ladies NYC Social July 2024

Clone github repository

Go to terminal (either in RStudio or on your computer).

Go to the working directory where you would like to put openbrewerydb data:

cd Documents

Then, type in the following command to clone the github repository using HTTPS:

git clone https://github.com/openbrewerydb/openbrewerydb.git

We are ready to use openbrewerydb!

Read in Data

Set your working directory to openbrewerydb. Make sure to specify your specific path:

# set working directory
setwd("/Users/nicole.burke/Documents/openbrewerydb")

# load packages
library(ggplot2)
library(leaflet)

Get a list of the files in openbrewerydb:

list.files("/Users/nicole.burke/Documents/openbrewerydb")
##  [1] "archive"                          "breweries.csv"                   
##  [3] "breweries.json"                   "breweries.sql"                   
##  [5] "CODE_OF_CONDUCT.md"               "CONTRIBUTING.md"                 
##  [7] "data"                             "LICENSE"                         
##  [9] "obdb-logo-md.jpg"                 "obdb-notebook.ipynb"             
## [11] "package-lock.json"                "package.json"                    
## [13] "R-Ladies openbrewerydb Demo.Rmd"  "R-Ladies-openbrewerydb-Demo.html"
## [15] "R-Ladies-openbrewerydb-Demo.Rmd"  "README.md"                       
## [17] "src"                              "tsconfig.json"

Let’s look at data from New York!

new_york <- read.csv("/Users/nicole.burke/Documents/openbrewerydb/data/united-states/new-york.csv")

str(new_york)
## 'data.frame':    418 obs. of  14 variables:
##  $ id            : chr  "d81ff708-b5d2-478f-af6a-6d40f5beb9ac" "ee6d39c6-092f-4623-8099-5b8643f70dbe" "4a09f017-db8f-42e1-a8ec-a0cd81c28761" "8624d11b-8593-49a8-89b4-c46a0f111cd7" ...
##  $ name          : chr  "12 Gates Brewing Company" "16 Stone Brewpub" "1940's Brewing Company" "2 Way Brewing Company" ...
##  $ brewery_type  : chr  "brewpub" "brewpub" "micro" "brewpub" ...
##  $ address_1     : chr  "80 Earhart Dr Ste 20" "9542 Main St" "1337 Lincoln Ave Unit 1" "18 W Main St" ...
##  $ address_2     : chr  "" "" "" "" ...
##  $ address_3     : logi  NA NA NA NA NA NA ...
##  $ city          : chr  "Williamsville" "Holland Patent" "Holbrook" "Beacon" ...
##  $ state_province: chr  "New York" "New York" "New York" "New York" ...
##  $ postal_code   : chr  "14221-7804" "13354" "11741-2275" "12508-2512" ...
##  $ country       : chr  "United States" "United States" "United States" "United States" ...
##  $ phone         : num  7.17e+09 3.16e+09 6.32e+09 8.45e+09 2.12e+09 ...
##  $ website_url   : chr  "http://www.12gatesbrewing.com" "http://www.16stonebrewpub.com" "http://www.1940sbrewingcompany.com" "http://www.2waybrewingcompany.com" ...
##  $ longitude     : num  NA -75.3 NA -74 NA ...
##  $ latitude      : num  NA 43.2 NA 41.5 NA ...
colnames(new_york)
##  [1] "id"             "name"           "brewery_type"   "address_1"     
##  [5] "address_2"      "address_3"      "city"           "state_province"
##  [9] "postal_code"    "country"        "phone"          "website_url"   
## [13] "longitude"      "latitude"

Plot where breweries are in New York State:

# Create a leaflet map
leaflet(data = new_york) %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers(~longitude, ~latitude, popup = ~paste("Brewery Location"))