-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
179 lines (117 loc) · 4.53 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
---
title: "zooplaR"
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
NOT_CRAN <- identical(tolower(Sys.getenv("NOT_CRAN")), "true")
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-",
purl = NOT_CRAN
)
```
[![Travis-CI Build Status](https://travis-ci.org/erzk/zooplaR.svg?branch=master)](https://travis-ci.org/erzk/zooplaR)
[![Coverage Status](https://img.shields.io/codecov/c/github/erzk/zooplaR/master.svg)](https://codecov.io/github/erzk/zooplaR?branch=master)
[![Package-License](http://img.shields.io/badge/license-GPL--3-brightgreen.svg?style=flat)](http://www.gnu.org/licenses/gpl-3.0.html)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/PostcodesioR)](https://cran.r-project.org/package=PostcodesioR)
### About
This package is an API wrapper for accessing the UK housing market data from [Zoopla](http://www.zoopla.co.uk/).
Check the package's [website](https://erzk.github.io/zooplaR/) for more examples.
### Installation
* Install *devtools* if you don't have it yet: `install.packages("devtools")`
* Use `devtools::install_github("erzk/zooplaR")` to install the package.
* Read the zooplaR's [vignette](https://github.com/erzk/zooplaR/blob/master/vignettes/Introduction_to_zooplaR.Rmd).
* [Register](http://developer.zoopla.com/member/register/) for an account and an API key.
* Store the key in an environment variable.
```{r, eval = FALSE}
file.edit("~/.Renviron")
```
Then create a variable in the `.Renviron` file like this:
```{r, eval = FALSE}
zoopla_key <- "YOUR_KEY_GOES_HERE"
```
For other options of storing a key, read this [vignette](https://cran.r-project.org/web/packages/httr/vignettes/secrets.html).
In my case, the API key is stored in the variable `zoopla_key`. You can check whether it's defined and loaded correctly and save it to a variable using:
```{r}
zoopla_key <- Sys.getenv("zoopla_key")
```
The functions in this package assume that the API key is stored in the system environment as a `zoopla_key` variable. If not, then most function calls will fail.
### Usage
Load the package
```{r}
library(zooplaR)
```
## Get the session id
This will be useful for other calls
```{r}
get_session_id(zoopla_key)
```
## Get the average property prices
Focus on a particular outcode:
```{r}
aasp <- average_area_sold_price("EH1 2NG", "outcode", zoopla_key)
# overview
str(aasp)
```
Or another use another function to focus on individual streets:
```{r}
asp <- average_sold_prices("EH1 2NG", "outcode", "streets", zoopla_key)
# overview
str(asp)
```
In the example above, the streets can be found in the URLs, e.g.
```{r}
asp[2]$areas$prices_url
```
## Zed indices
Zoopla prepared its own indices, they can be accessed with the following functions:
```{r}
zi <- zed_index("E151AZ", "town", zoopla_key)
# overview
str(zi)
```
Function `zed_index()` can also provide indices on other aggregation levels. Please consult documentation for more info.
There is also another zed index function that takes more arguments:
```{r}
azi <- area_zed_indices("sw185rw", "postcodes", "outcode", 1, 10, zoopla_key, "descending")
# overview
str(azi)
```
## Property listings
You can get the Zoopla listings for a particular area using the following call:
```{r}
listings <- property_listings(postcode = "E15 4QS", API_key = zoopla_key)
# overview
names(listings)
str(listings[6])
```
## Get house price charts
Chart showing prices in the last three months in a particular outcode:
```{r}
avgr <- area_value_graphs("W12", zoopla_key)
# overview
str(avgr)
# to see a chart, follow the URLs, e.g.
avgr$average_values_graph_url
```
More detailed charts can also include information about council tax, crime, education, or population age range. These charts can be generated by Zoopla using the following also on an incode level.
```{r}
ligr <- local_info_graphs("W12", zoopla_key)
# overview
str(ligr)
# to see a chart, follow the URLs, e.g.
ligr$council_tax_graph_url
```
## Suggest autocompletions for locations
If you are not sure how to spell a location, you can use the API to get suggestions. On this example I made a typo when writing Ruislip:
```{r}
geo_ac <- geo_autocomplete("ruisli", "listings", zoopla_key)
# overview
str(geo_ac)
```
### Limitations
As most APIs, Zoopla [limits](http://developer.zoopla.com/API_terms_of_use) the number of calls. The limit is 100 calls per second and 100 per hour. Once you hit the limit, the 403 error will appear.
### Thanks
![](https://www.zoopla.co.uk/static/images/mashery/powered-by-zoopla-150x73.png)