isoband/ 0000755 0001762 0000144 00000000000 14073215605 011674 5 ustar ligges users isoband/NAMESPACE 0000644 0001762 0000144 00000001277 14073124476 013127 0 ustar ligges users # Generated by roxygen2: do not edit by hand
S3method(iso_to_sfg,default)
S3method(iso_to_sfg,isobands)
S3method(iso_to_sfg,isolines)
S3method(makeContent,isobands_grob)
S3method(makeContent,isolines_grob)
S3method(makeContext,isolines_grob)
export(angle_fixed)
export(angle_halfcircle_bottom)
export(angle_halfcircle_right)
export(angle_identity)
export(clip_lines)
export(iso_to_sfg)
export(isobands)
export(isobands_grob)
export(isolines)
export(isolines_grob)
export(label_placer_manual)
export(label_placer_middle)
export(label_placer_minmax)
export(label_placer_none)
export(label_placer_simple)
export(plot_iso)
import(grid)
importFrom(utils,modifyList)
useDynLib(isoband, .registration = TRUE)
isoband/LICENSE 0000644 0001762 0000144 00000000054 13501223536 012675 0 ustar ligges users YEAR: 2019
COPYRIGHT HOLDER: Claus O. Wilke
isoband/README.md 0000644 0001762 0000144 00000007262 14017542230 013155 0 ustar ligges users
# isoband
[](https://github.com/wilkelab/isoband/actions)
[](https://codecov.io/github/wilkelab/isoband?branch=master)
[](https://cran.r-project.org/package=isoband)
[](https://lifecycle.r-lib.org/articles/stages.html)
Generate contour lines (isolines) and contour polygons (isobands) from
regularly spaced grids containing elevation data.
## Installation
Install the latest official release from CRAN via:
``` r
install.packages("isoband")
```
Install the current development from github via:
``` r
remotes::install_github("wilkelab/isoband")
```
## Examples
The two main workhorses of the package are the functions `isolines()`
and `isobands()`, respectively. They return a list of isolines/isobands
for each isolevel specified. Each isoline/isoband consists of vectors of
x and y coordinates, as well as a vector of ids specifying which sets of
coordinates should be connected. This format can be handed directly to
`grid.polyline()`/`grid.path()` for drawing. However, we can also
convert the output to spatial features and draw with ggplot2 (see
below).
``` r
library(isoband)
m <- matrix(c(0, 0, 0, 0, 0,
0, 1, 2, 1, 0,
0, 1, 2, 0, 0,
0, 1, 0, 1, 0,
0, 0, 0, 0, 0), 5, 5, byrow = TRUE)
isolines(1:ncol(m), 1:nrow(m), m, 0.5)
#> $`0.5`
#> $`0.5`$x
#> [1] 4.00 3.50 3.00 2.50 2.00 1.50 1.50 1.50 2.00 3.00 4.00 4.50 4.00 3.75 4.00
#> [16] 4.50 4.00
#>
#> $`0.5`$y
#> [1] 4.50 4.00 3.75 4.00 4.50 4.00 3.00 2.00 1.50 1.25 1.50 2.00 2.50 3.00 3.50
#> [16] 4.00 4.50
#>
#> $`0.5`$id
#> [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#>
#>
#> attr(,"class")
#> [1] "isolines" "iso"
isobands(1:ncol(m), 1:nrow(m), m, 0.5, 1.5)
#> $`0.5:1.5`
#> $`0.5:1.5`$x
#> [1] 2.50 2.00 1.50 1.50 1.50 2.00 3.00 4.00 4.50 4.00 3.75 4.00 4.50 4.00 3.50
#> [16] 3.00 3.00 3.25 3.50 3.00 2.50 2.50
#>
#> $`0.5:1.5`$y
#> [1] 4.00 4.50 4.00 3.00 2.00 1.50 1.25 1.50 2.00 2.50 3.00 3.50 4.00 4.50 4.00
#> [16] 3.75 3.25 3.00 2.00 1.75 2.00 3.00
#>
#> $`0.5:1.5`$id
#> [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
#>
#>
#> attr(,"class")
#> [1] "isobands" "iso"
```
The function `plot_iso()` is a convenience function for debugging and
testing.
``` r
plot_iso(m, 0.5, 1.5)
```
The isolining and isobanding algorithms have no problem with larger
datasets. Let’s calculate isolines and isobands for the volcano dataset,
convert to sf, and plot with ggplot2.
``` r
library(ggplot2)
suppressWarnings(library(sf))
#> Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1
m <- volcano
b <- isobands((1:ncol(m))/(ncol(m)+1), (nrow(m):1)/(nrow(m)+1), m, 10*(9:19), 10*(10:20))
l <- isolines((1:ncol(m))/(ncol(m)+1), (nrow(m):1)/(nrow(m)+1), m, 10*(10:19))
bands <- iso_to_sfg(b)
data_bands <- st_sf(
level = 1:length(bands),
geometry = st_sfc(bands)
)
lines <- iso_to_sfg(l)
data_lines <- st_sf(
level = 2:(length(lines)+1),
geometry = st_sfc(lines)
)
ggplot() +
geom_sf(data = data_bands, aes(fill = level), color = NA, alpha = 0.7) +
geom_sf(data = data_lines, color = "black") +
scale_fill_viridis_c(guide = "none") +
coord_sf(expand = FALSE)
```
isoband/man/ 0000755 0001762 0000144 00000000000 14070653241 012446 5 ustar ligges users isoband/man/clip_lines.Rd 0000644 0001762 0000144 00000002041 13501223537 015052 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/clip-lines.R
\name{clip_lines}
\alias{clip_lines}
\title{Clip lines so they don't run into a set of boxes.}
\usage{
clip_lines(x, y, id, clip_boxes, asp = 1)
}
\arguments{
\item{x}{Numeric vector of x coordinates}
\item{y}{Numeric vector of y coordinates}
\item{id}{Integer vector of id numbers indicating which lines are connected}
\item{clip_boxes}{Data frame specifying the locations of boxes to clip to.
Should have five columns, named \code{x}, \code{y}, \code{width}, \code{height}, \code{theta}, which
specify the x and y positions of each box midpoint, as well as the box width,
box height, and box angle in radians. Each box is specified by one data
row.}
\item{asp}{Aspect ratio (width/height) of the target canvas. This is used to convert
widths to heights and vice versa for rotated boxes}
}
\description{
Clip lines so they don't run into a set of boxes. Useful for labeling isolines,
as it allows removal of line segments that would run into any text labels.
}
isoband/man/label_placer.Rd 0000644 0001762 0000144 00000003143 14064403653 015346 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/label-placer.R
\name{label_placer_minmax}
\alias{label_placer_minmax}
\alias{label_placer_none}
\alias{label_placer_manual}
\alias{label_placer_middle}
\title{Set up a label placement strategy}
\usage{
label_placer_minmax(
placement = "tb",
rot_adjuster = angle_halfcircle_bottom(),
n = 2
)
label_placer_none()
label_placer_manual(breaks, x, y, theta)
label_placer_middle(rot_adjuster = angle_halfcircle_bottom())
}
\arguments{
\item{placement}{String consisting of any combination of the letters
"t", "r", "b", "l" indicating the placement of labels at the top,
to the right, at the bottom, to the left of the isoline.}
\item{rot_adjuster}{Function that standardizes the rotation angles of the labels.
See e.g. \code{\link[=angle_halfcircle_bottom]{angle_halfcircle_bottom()}}.}
\item{n}{Size of the point neighborhood over which the rotation angle should be
calculated.}
\item{breaks}{Character vector specifying the isolines to be labeled,
as in \code{\link[=isolines_grob]{isolines_grob()}}.}
\item{x, y, theta}{Numeric vectors specifying the x and y positions and
angles (in radians) for each label corresponding to each break.}
}
\description{
These functions set up various label placement strategies.
}
\details{
\code{label_placer_minmax()} places labels at the horizontal or vertical minima or maxima of
the respective isolines.
\code{label_placer_none()} places no labels at all.
\code{label_placer_manual()} places labels at manually defined locations.
\code{label_placer_middle()} places labels at the middle of each isoline.
}
isoband/man/isolines_grob.Rd 0000644 0001762 0000144 00000005502 13644532420 015576 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/isolines-grob.R
\name{isolines_grob}
\alias{isolines_grob}
\title{Render labeled isolines}
\usage{
isolines_grob(
lines,
gp = gpar(),
breaks = NULL,
labels = NULL,
margin = unit(c(1, 1, 1, 1), "pt"),
label_col = NULL,
label_alpha = NULL,
label_placer = label_placer_minmax(),
units = "npc"
)
}
\arguments{
\item{lines}{Isolines, as produced by the \code{\link[=isolines]{isolines()}} function.}
\item{gp}{Grid graphical parameters. Parameters applying to lines
(such as \code{col}, \code{lwd}, \code{lty}, etc.) are recycled among the total
number of lines drawn. Parameters applying only to labels (such
as \code{fontfamily}, \code{fontsize}) are recycled among the specified
breaks only. The two parameters \code{col} and \code{alpha} are also applied
to labels, unless overridden (see \code{label_col} and \code{label_alpha}),
but are matched to the corresponding lines.}
\item{breaks}{Character vector specifying the isolines that should be
labeled. If \code{NULL}, labels all isolines.}
\item{labels}{Character vector specifying the labels for each break.
If \code{NULL}, uses the breaks as labels. The number of labels provided
must match the number of breaks provided.}
\item{margin}{Unit object of length 4 specifying the top, right, bottom,
and left margins around each text label. The same margins are applied
to all labels.}
\item{label_col}{Color applied to labels. Can be used to override the
color provided in \code{gp}, in case labels and lines should have different
colors.}
\item{label_alpha}{Alpha applied to labels. Can be used to override the
alpha value provided in \code{gp}, in case labels and lines should have
different alpha values.}
\item{label_placer}{Function that controls how labels are placed along
the isolines. Uses \code{\link[=label_placer_minmax]{label_placer_minmax()}} by default.}
\item{units}{A character string specifying the units in which to
interpret the isolines coordinates. Defaults to \code{"npc"}.}
}
\description{
This function generates a grid grob that represents labeled isolines.
}
\examples{
library(grid)
viridis_pal <- colorRampPalette(
c("#440154", "#414487", "#2A788E", "#22A884", "#7AD151", "#FDE725"),
space = "Lab"
)
x <- (1:ncol(volcano))/(ncol(volcano)+1)
y <- (nrow(volcano):1)/(nrow(volcano)+1)
lines <- isolines(x, y, volcano, 5*(19:38))
bands <- isobands(x, y, volcano, 5*(18:38), 5*(19:39))
b <- isobands_grob(
bands,
gp = gpar(col = NA, fill = viridis_pal(21), alpha = 0.4)
)
l <- isolines_grob(
lines, breaks = 20*(5:10),
gp = gpar(
lwd = c(.3, 1, .3, .3)
)
)
grid.newpage()
grid.draw(b)
grid.draw(l)
}
\seealso{
See \code{\link[=isobands_grob]{isobands_grob()}} for drawing of isobands. See \code{\link[=label_placer_minmax]{label_placer_minmax()}} for
label placement strategies.
}
isoband/man/figures/ 0000755 0001762 0000144 00000000000 14017542227 014114 5 ustar ligges users isoband/man/figures/README-volcano-1.png 0000644 0001762 0000144 00001021145 14017542227 017360 0 ustar ligges users PNG
IHDR _ iCCPkCGColorSpaceGenericRGB 8U]hU>sg#$Sl4t?
%
V46nI6"dΘ83OEP|1Ŀ (>/
% (>P苦;3ie|{g蹪X-2s=+WQ+]L6Ow[C{_F qbUvz?Zb1@/zcs>~if,ӈUSjF1_Mjbuݠpamhmçϙ>a\+5%QKFkm}ۖ?ޚD\!~6,-7SثŜvķ5Z;[rmS5{yDyH}r9|-ăFAJjI.[/]mK7KRDrYQO-Q||6
(0
MXd(@h2_f<:_δ*d>e\c?~,7?& ك^2Iq2"y