-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
110 lines (77 loc) · 3.99 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
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- 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%"
)
```
# graticule
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/graticule)](https://CRAN.R-project.org/package=graticule)
[![R-CMD-check](https://github.com/hypertidy/graticule/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/hypertidy/graticule/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
Graticules are the longitude latitude lines shown on a projected map, and defining and drawing these lines is not easy to automate. The graticule package provides the tools to create and draw these lines by explicit specification by the user. This provides a good compromise between high-level automation and the flexibility to drive the low level details as needed, using base graphics in R.
## Installation
You can install the released version of graticule from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("graticule")
```
And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("hypertidy/graticule")
```
## Example
This is a basic example which shows how to create a graticule at specific longitude and latitude spacings
and in a given projection.
```{r example}
library(graticule)
grat <- graticule(lons = seq(100, 220, by = 15), lats = seq(-60, -10, by = 5), proj = "+proj=laea +lon_0=140 +lat_0=-90 +datum=WGS84")
plot(grat)
```
There is an automatic segmentation that is done at equal distances along these [rhumb lines](https://en.wikipedia.org/wiki/Rhumb_line). This is not an *[ideal spacing](https://bost.ocks.org/mike/example/)* but is an improvement on the common alternatives, and is easier to work with when you need fine control.
If your projection is not wildly warped in most areas then the default rhumb line segmentation is the best first step.
```{r rhumb-points}
plot(as(grat, "SpatialPoints"))
```
This also allows the common case of creating a sensible single polygon *wedge*, i.e.
```{r wedge}
wedge <- graticule(lons = c(-40, 40), lats = c(-60, -40), proj = "+proj=laea +lat_0=-50 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs")
plot(wedge)
points(as(wedge, "SpatialPoints"))
```
## Quick and dirty plot
Give it a raster and let it plot, can provide `levels` as per contour (values of longitude or latitude to draw as lines), and separate longitude or latitude plot on their own.
Sometimes it's enough, sometimes we can muck around to get what we want.
```{r lonlat}
tfile <- system.file("extdata", "nt_20140320_f17_v01_s.bin", package = "graticule", mustWork = TRUE)
ice <- raster::raster(tfile)
ice[!ice > 0] <- NA
raster::plot(ice, col = palr::ice_pal(100))
lonlat(ice)
raster::plot(ice, col = palr::ice_pal(100))
lonlat(ice, lon = TRUE, levels = seq(-180, 165, by = 15))
lonlat(ice, lat = TRUE, levels = seq(-85, -40, by = 5))
## not much good so let's get the actual arrays
lon <- lonlat(ice, plot = FALSE)[[1]]
lat <- lonlat(ice, plot = FALSE)[[2]]
lon[lat < -85] <- NA
raster::plot(ice, col = palr::ice_pal(100))
raster::contour(lon, add = TRUE)
lonlat(ice, lat = TRUE, levels = seq(-85, -40, by = 5))
```
## Known Issues
Please feel free to share your experiences and report problems at https://github.com/hypertidy/graticule/issues
* general problems with segmentation, this is not done smartly yet (see hypertidy/bigcurve or the s2 package)
* There's work needed for when `graticule_labels()` are created without using `xline/yline`, need more careful separation between generating every combination in the grid versus single lines
---
Please note that the 'graticule' project is released with a
[Contributor Code of Conduct](https://github.com/hypertidy/graticule/blob/master/CODE_OF_CONDUCT.md).
By contributing to this project, you agree to abide by its terms.