-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
103 lines (76 loc) · 3.5 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
set.seed(2022)
```
# ggautomap
<!-- badges: start -->
[![ggautomap status badge](https://cidm-ph.r-universe.dev/badges/ggautomap)](https://cidm-ph.r-universe.dev)
[![R-CMD-check](https://github.com/cidm-ph/ggautomap/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/cidm-ph/ggautomap/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
`ggautomap` helps when you have a spreadsheet/table of data that includes a
column of place names, and you want to visualise that data on a map. It saves
you from having to think about geospatial libraries when all you want to do
is make a quick plot from your spreadsheet.
See [the 'Getting started' article](https://cidm-ph.github.io/ggautomap/articles/ggautomap.html),
`vignette("ggautomap")`, for some recipes for different types of plots it can make.
`ggautomap` works best if:
- your data is about regions/areas/countries etc.,
- each row corresponds to an individual observation or data point, and
- the locations names in your data are part of a map that is registered with
`{cartographer}`.
`ggautomap` might not be right for you if ...
- ... the place names in your location column aren't known to `{cartographer}`.
You'll have to register the map data with `cartographer::register_map()` or
load a package that does this for you. This is fairly painless to set up,
and can be reused for subsequent plots once you get it working.
- ... your data is about points instead of regions, or has only a single row
for each region with aggregate data.
- ... your data has latitude and longitude columns, or is already a geospatial
object such as an `{sf}` dataframe.
- ... you want to manipulate the geometries or otherwise have more control.
`ggautomap` is aimed at the simple case, so the geometries are attached on
the fly when the plot is compiled.
In most of these cases, you should instead use a combination of `{sf}`,
`ggplot2::geom_sf()`, and possibly `{cartographer}` to have more direct control.
If you just want the map insets from the vignette, see `{ggmapinset}`.
## Installation
You can install ggautomap like so:
``` r
# CRAN release
install.packages('ggautomap')
# development version
install.packages('ggautomap', repos = c('https://cidm-ph.r-universe.dev', 'https://cloud.r-project.org'))
```
## Example
Let's use the example dataset from `{cartographer}`:
```{r}
library(cartographer)
head(nc_type_example_2)
```
A possible workflow is to use `cartographer::add_geometry()` to convert this
into a spatial data frame and then use `ggplot2::geom_sf()` to draw it.
`ggautomap` instead provides geoms that do this transparently as needed, so you
don't need to do a lot of boilerplate to wrangle the data into the right form
before handing it off to the plotting code.
```{r example-basic, fig.width=8, fig.height=3}
library(ggplot2)
library(ggautomap)
ggplot(nc_type_example_2, aes(location = county)) +
geom_boundaries(feature_type = "sf.nc") +
geom_geoscatter(aes(colour = type), size = 0.5) +
coord_automap(feature_type = "sf.nc")
ggplot(nc_type_example_2, aes(location = county)) +
geom_choropleth() +
geom_boundaries(feature_type = "sf.nc") +
scale_fill_steps(low = "#e6f9ff", high = "#00394d", na.value = "white") +
coord_automap(feature_type = "sf.nc")
```