-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
101 lines (81 loc) · 3.16 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
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "70%",
fig.ext = "svg",
dev = "ggsave"
)
```
# ggfields
## Overview
<!-- badges: start -->
[![R-CMD-check](https://github.com/pepijn-devries/ggfields/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/pepijn-devries/ggfields/actions/workflows/R-CMD-check.yaml)
![cranlogs](https://cranlogs.r-pkg.org/badges/ggfields)
[![version](https://www.r-pkg.org/badges/version/ggfields)](https://CRAN.R-project.org/package=ggfields)
[![cran checks](https://badges.cranchecks.info/worst/ggfields.svg)](https://cran.r-project.org/web/checks/check_results_ggfields.html)
[![ggfields status badge](https://pepijn-devries.r-universe.dev/badges/ggfields)](https://pepijn-devries.r-universe.dev/ggfields)
[![codecov](https://codecov.io/gh/pepijn-devries/ggfields/graph/badge.svg?token=M8DRDR80RL)](https://codecov.io/gh/pepijn-devries/ggfields)
<!-- badges: end -->
<img src="man/figures/logo.png" align="right" alt = "logo" class = "pkgdown-hide" />
Add vector field layers to your `ggplot2::ggplot()`. Although it has similarities
with `ggplot2::geom_spoke()`, `ggfields` offers some distinct features:
* The `radius` aesthetic is mapped to a scale and therefore can be added
to the guides (see `vignette("radius_aes")`).
* Not only `data.frame`s are supported, but also geometric data
(`sf::st_sf()` and `stars::st_as_stars()`).
* Corrects angles for displayed aspect ratio or coordinate system
(see `vignette("angle_correction")`).
## Installation
> Get CRAN version
```{r eval=FALSE}
install.packages("ggfields")
```
> Get development version from r-universe
```{r eval=FALSE}
install.packages("ggfields", repos = c("https://pepijn-devries.r-universe.dev", "https://cloud.r-project.org"))
```
## Adding vector fields to a map
The example below shows how seawater current data can be added to a map:
```{r init, results = 'hide', message = FALSE}
library(ggplot2)
library(ggfields)
library(ggspatial) ## For annotating with Open Street Map
```
```{r theme, echo = FALSE}
theme_set(theme_light())
set.seed(0)
```
```{r map, results = 'hide', message = FALSE, fig.width = 5, fig.height = 7, out.width = "50%"}
data(seawatervelocity)
ggplot() +
ggspatial::annotation_map_tile(
alpha = 0.25,
cachedir = tempdir()) +
geom_fields(
data = seawatervelocity,
aes(radius = as.numeric(v),
angle = as.numeric(angle),
colour = as.numeric(v)),
max_radius = grid::unit(0.7, "cm")) +
labs(colour = "v[m/s]",
radius = "v[m/s]") +
scale_radius_binned() +
scale_colour_viridis_b(guide = guide_bins())
```
## Simple data.frames
Vector arrows can also be added to simple plots with `x` and `y` data:
```{r dataframe, results = 'hide', message = FALSE}
## First generate some arbitrary data to plot:
n <- 10
df <- data.frame(x = seq(0, 100, length.out = n), y = rnorm(n),
ang = seq(0, 2*pi, length.out = n))
df$len <- 2 + df$y + rnorm(n)/4
ggplot(df, aes(x = x, y = y)) +
geom_line() +
geom_fields(aes(angle = ang, radius = len), .angle_correction = NULL)
```