comparison visualize.r @ 0:1015a0070bac draft

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