forked from dkahle/ggmap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
76 lines (52 loc) · 2.24 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
---
output:
md_document:
variant: markdown_github
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "figures/README-"
)
```
# ggmap
**ggmap** makes it easy to retrieve raster map tiles from popular online mapping services like [Google Maps](https://developers.google.com/maps/documentation/static-maps/?hl=en), [OpenStreetMap](https://www.openstreetmap.org), [Stamen Maps](http://maps.stamen.com), and plot them using the **ggplot2** framework:
```{r maptypes, message = FALSE}
library(ggmap)
us <- c(left = -125, bottom = 25.75, right = -67, top = 49)
map <- get_stamenmap(us, zoom = 5, maptype = "toner-lite")
ggmap(map)
ggmap(map, extent = "device")
```
Use `qmplot()` in the same way you'd use `qplot()`, but with a map automatically added in the background:
```{r qmplot, message=FALSE}
downtown <- subset(crime,
-95.39681 <= lon & lon <= -95.34188 &
29.73631 <= lat & lat <= 29.78400
)
qmplot(lon, lat, data = downtown, maptype = "toner-background", color = I("red"))
qmplot(lon, lat, data = downtown, maptype = "toner-lite", geom = "density2d", color = I("red"))
```
Since **ggmap**'s built on top of **ggplot2**, all your usual **ggplot2** stuff (geoms, polishing, etc.) will work, and there are some unique graphing perks **ggmap** brings to the table, too.
```{r styling, message=FALSE}
robberies <- subset(downtown, offense == "robbery")
qmplot(lon, lat, data = downtown, geom = "blank", zoom = 15, maptype = "toner-background", darken = .7) +
stat_density_2d(aes(fill = ..level..), geom = "polygon", alpha = .3, color = NA) +
scale_fill_gradient2("Robbery\nPropensity", low = "white", mid = "yellow", high = "red", midpoint = 1500)
```
Faceting works, too:
```{r faceting, message=FALSE}
qmplot(lon, lat, data = downtown, maptype = "toner-background", color = offense) +
facet_wrap(~ offense)
```
For convenience, here's a map of Europe:
```{r europe, message=FALSE}
europe <- c(left = -12, bottom = 35, right = 30, top = 63)
map <- get_stamenmap(europe, zoom = 5, maptype = "toner-lite")
ggmap(map)
```
## Installation
* From CRAN: `install.packages("ggmap")`
* From Github: `devtools::install_github("dkahle/ggmap")`