-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
100 lines (77 loc) · 3.69 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
---
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-"
)
```
# maplegend
<!-- badges: start -->
[![R-CMD-check](https://github.com/riatelab/maplegend/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/riatelab/maplegend/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/riatelab/maplegend/branch/main/graph/badge.svg)](https://app.codecov.io/gh/riatelab/maplegend?branch=main)
[![Project Status: Active – The project has reached a stable, usable
state and is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
<!-- badges: end -->
Create legends for maps and other graphics. Thematic maps need to be accompanied by legible legends to be fully comprehensible. This package offers a wide range of legends useful for cartography, some of which may also be useful for other types of graphics.
## Installation
You can install the released version of `maplegend` from
CRAN with:
``` r
install.packages("maplegend")
```
Alternatively, you can install the development version of `maplegend` from
GitHub (**dev** branch) with:
``` r
remotes::install_github("riatelab/maplegend", ref = "dev")
```
## Example
The main function is `leg()`. Its `type` argument defines the legend type.
```{r example, fig.width=9, fig.height=4.5, fig.show="hold"}
library(maplegend)
opar <- par(mar = c(1, 1, 1, 1), mfrow = c(1, 2))
plot.new()
plot.window(xlim = c(0, 1), ylim = c(0, 1), asp = 1)
leg(type = "prop", val = c(10, 50, 100), pos = "topleft")
leg(type = "choro", val = c(10, 20, 30, 40, 50), pos = "bottomleft")
leg(type = "typo", val = c("A", "B", "C"), pos = "top")
leg(type = "symb", val = c("A", "B", "C"), pos = "topright")
leg(type = "prop_line", val = c(5, 50, 100), pos = "bottom", lwd = 20)
leg(type = "grad_line", val = c(1, 4, 10, 15), pos = "bottomright", lwd = c(1, 5, 10))
box()
plot.new()
plot.window(xlim = c(0, 100), ylim = c(-50, 50), asp = 1)
leg(type = "prop", val = c(10, 50, 100), pos = "topleft", horiz = TRUE)
leg(type = "choro", val = c(10, 20, 30, 40, 50), pos = "left", horiz = TRUE)
leg(type = "cont", val = c(10, 20, 30, 40, 50), pos = "bottomleft", horiz = TRUE)
leg(type = "cont", val = c(10, 20, 30, 40, 50), pos = c(75, 0), horiz = FALSE)
leg(type = "symb", val = c("Points", "Lines", "Polygons"), pos = "topright",
pch = list(21, "৲", 22), cex = c(2,2,2), border = c("black", "black"),
pal = c("red", "blue", "grey90"))
box()
```
It is possible to create composed legends with `leg_comp()` and `leg_draw()`.
```{r example2, fig.width=4.5, fig.height=4.5, fig.show="hold"}
opar <- par(mar = c(1, 1, 1, 1))
plot.new()
plot.window(xlim = c(0, 1), ylim = c(0, 1), asp = 1)
leg_comp(type = "prop", val = c(10, 50, 100)) |>
leg_comp(type = "typo", val = c("A", "B", "C")) |>
leg_draw(pos = "top", bg = "lightblue", fg = "darkblue", frame_border = NA)
box()
par(opar)
```
## Background
This package is mainly intended for the construction of legends in the [`mapsf`](https://riatelab.github.io/mapsf/) package.
However, it can also be used independently of `mapsf` with `base` plots or even with [`igraph` plots](https://gist.github.com/rCarto/da5a4b0cd982a8c85cb847506fd2f415).
## Community Guidelines
One can contribute to the package through [pull
requests](https://github.com/riatelab/maplegend/pulls) and report issues or
ask questions [here](https://github.com/riatelab/maplegend/issues).
This project uses [conventional
commits](https://www.conventionalcommits.org/en/v1.0.0-beta.3/) and
[semantic versioning](https://semver.org/).