Mercurial > repos > ecology > obis_data
annotate visualize.r @ 1:5bae75c49f2e draft default tip
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit 13ac67c0a21d742b29e6273cdff058560abad770
author | ecology |
---|---|
date | Tue, 05 Nov 2024 14:17:49 +0000 |
parents | 1fcd81d65467 |
children |
rev | line source |
---|---|
0
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
1 #' Statically map indicators using ggplot |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
2 #' |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
3 #' @param grid spatial features, e.g. hexagons, to plot; requires a geometry |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
4 #' spatial column |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
5 #' @param column column name with indicator; default="shannon" |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
6 #' @param label label to show on legend |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
7 #' @param crs coordinate reference system; see `sf::st_crs()` |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
8 #' @param trans For continuous scales, the name of a transformation object or |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
9 #' the object itself. Built-in transformations include "asn", "atanh", |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
10 #' "boxcox", "date", "exp", "hms", "identity" (default), "log", "log10", "log1p", |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
11 #' "log2", "logit", "modulus", "probability", "probit", "pseudo_log", |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
12 #' "reciprocal", "reverse", "sqrt" and "time". See `ggplot2::continuous_scale` |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
13 #' |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
14 #' @return ggplot2 plot |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
15 #' @concept visualize |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
16 #' @export |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
17 #' @import rnaturalearth viridis ggplot2 |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
18 #' |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
19 #' @examples |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
20 gmap_indicator <- function( |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
21 grid, column = "shannon", label = "Shannon index", trans = "identity", |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
22 crs = "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs") { |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
23 |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
24 world <- rnaturalearth::ne_countries(scale = "medium", returnclass = "sf") |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
25 bb <- sf::st_bbox( |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
26 sf::st_transform(grid, crs)) |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
27 |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
28 ggplot2::ggplot() + |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
29 ggplot2::geom_sf( |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
30 data = grid, ggplot2::aes_string( |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
31 fill = column, geometry = "geometry"), lwd = 0) + |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
32 viridis::scale_color_viridis( |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
33 option = "inferno", na.value = "white", |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
34 name = label, trans = trans) + |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
35 viridis::scale_fill_viridis( |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
36 option = "inferno", na.value = "white", |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
37 name = label, trans = trans) + |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
38 ggplot2::geom_sf( |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
39 data = world, fill = "#dddddd", color = NA) + |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
40 ggplot2::theme( |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
41 panel.grid.major.x = ggplot2::element_blank(), |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
42 panel.grid.major.y = ggplot2::element_blank(), |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
43 panel.grid.minor.x = ggplot2::element_blank(), |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
44 panel.grid.minor.y = ggplot2::element_blank(), |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
45 panel.background = ggplot2::element_blank(), |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
46 axis.text.x = ggplot2::element_blank(), |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
47 axis.text.y = ggplot2::element_blank(), |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
48 axis.ticks = ggplot2::element_blank(), |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
49 axis.title.x = ggplot2::element_blank(), |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
50 axis.title.y = ggplot2::element_blank()) + |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
51 ggplot2::xlab("") + ggplot2::ylab("") + |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
52 ggplot2::coord_sf( |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
53 crs = crs, |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
54 xlim = bb[c("xmin", "xmax")], |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
55 ylim = bb[c("ymin", "ymax")]) |
1fcd81d65467
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
ecology
parents:
diff
changeset
|
56 } |