Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/earowang/rwalkr

R package to provide API to Melbourne pedestrian data
https://github.com/earowang/rwalkr

r web-scraper

Last synced: 3 months ago
JSON representation

R package to provide API to Melbourne pedestrian data

Awesome Lists containing this project

README

        

---
output:
github_document:
html_preview: false
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE, message = FALSE,
comment = "#>",
fig.path = "man/figures/"
)
options(tibble.print_min = 5)
```

[![Travis-CI Build Status](https://travis-ci.org/earowang/rwalkr.svg?branch=master)](https://travis-ci.org/earowang/rwalkr)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/rwalkr)](https://cran.r-project.org/package=rwalkr)
[![Downloads](http://cranlogs.r-pkg.org/badges/rwalkr?color=brightgreen)](https://cran.r-project.org/package=rwalkr)

# rwalkr

The goal of **rwalkr** is to provide APIs to the pedestrian and microclimate data from the City of Melbourne in tidy data form.

## Installation

You could install the stable version from CRAN:

```{r, eval = FALSE}
install.packages("rwalkr")
```

You could install the development version from Github using:

```{r, eval = FALSE}
# install.packages("devtools")
devtools::install_github("earowang/rwalkr")
```

## Usage

### APIs

There are two APIs available to access hourly Melbourne pedestrian data: *compedapi* and *Socrata*. The former drives the `melb_walk()` function, where counts are uploaded on a daily basis; the latter powers the `melb_walk_fast()` function, where counts are uploaded on a monthly basis. Given the function names, the function `melb_walk_fast()` pulls the data at a much faster speed than `melb_walk()`.

The function `melb_walk()` specifies the starting and ending dates to be pulled, whereas `melb_walk_fast()` requires years to define the time frame. If a selection of sensors are of interest, `melb_walk_fast()` provides the flexibility for sensor choices.

```{r data}
library(rwalkr)
start_date <- as.Date("2017-07-01")
ped_walk <- melb_walk(from = start_date, to = start_date + 6L)
ped_walk
ped_run <- melb_walk_fast(year = 2016:2017, sensor = NULL) # NULL means all sensors
ped_run
```

There are missing values (i.e. `NA`) in the dataset. By setting `na.rm = TRUE` in both functions, missing values will be removed.

Here's an example to use *ggplot2* for visualisation:

```{r plot, fig.height = 4}
library(ggplot2)
ggplot(data = subset(ped_walk, Sensor == "Melbourne Central")) +
geom_line(aes(x = Date_Time, y = Count))
```

To access minute by minute directional pedestrian counts for the last hour, please check out the `melb_walk_directional()`.

It's recommended to include an application token in `melb_walk_fast(app_token = "YOUR-APP-TOKEN")`, which you can sign up [here](https://data.melbourne.vic.gov.au/profile/app_tokens).

### Shiny app

The function `melb_shine()` launches a shiny app to give a glimpse of the data. It provides two basic plots: one is an overlaying time series plot, and the other is a dot plot indicating missing values. Below is a screen-shot of the shiny app.

![](man/figures/shiny.png)