forked from sebastianbarfort/mapDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
76 lines (49 loc) · 2.33 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
# mapDK
```{r global_options, include = FALSE}
library(knitr)
options(width = 120)
opts_chunk$set(fig.width = 12, fig.height = 8, fig.path = 'figure/',
include = TRUE, warning = FALSE, message = FALSE)
```
This is a very incomplete draft of a mapDK package for making easy ggplot2 based maps of Denmark.
Currently, the package allows you to do two things:
1. make basic maps of DK at the municipality or parish level
2. turn these maps into (static) choropleth maps
I will make it possible to create interactive choropleth maps when R's interactive libraries such as [rCharts](https://github.com/ramnathv/rCharts), [leaftletR](https://github.com/rstudio/leaflet), or [ggvis](https://github.com/rstudio/ggvis), mature a little.
I will also add more maps with time. First on my list is probably municipalities from before the Danish municipality reform of 2005, but suggestions are welcome.
To install the package simply run
```{r}
devtools::install_github("sebastianbarfort/mapDK")
````
To use the basic map simply run
```{r}
library(mapDK)
mapDK()
````
The default plots Denmark's 98 municipalities. You can plot at the parish level by adding `detail = "parish"` in the `mapDK` call
```{r}
mapDK(detail = "parish")
````
To create a static choropleth map I've added some test data to the package.
We can create a map by simply specifying the values and id's (as strings) and the dataset in the call to `mapDK`
```{r}
mapDK(values = "indbrud", id = "kommune", data = test.data)
````
If you don't provide names for all municipalities (or parishes), the function will throw a warning. Let's randomly remove 20 rows and plot the data again
```{r}
test.data.2 = mapDK::test.data[-sample(1:nrow(mapDK::test.data), 20), ]
mapDK(values = "indbrud", id = "kommune", data = test.data.2)
```
You can remove missing municipalities by changing `show_missing` to false and you can add a custom legend title by specifying the `guide.label` option
```{r}
mapDK(values = "indbrud", id = "kommune", data = test.data.2, show_missing = FALSE,
guide.label = "test label")
```
You can also provide a `sub` option specifying what municipalities in your data you want plotted
```{r}
mapDK(values = "indbrud", id = "kommune", data = test.data, sub = c("Viborg", "Esbjerg"))
```
This also works for non-choropleth maps
```{r}
mapDK(sub = c("Viborg", "Esbjerg"))
```