Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions R/velocityplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
#' @param streamline_minl A numeric value specifying the minimum streamline length. Shorter streamlines are not drawn. Passed to \code{\link[metR]{geom_streamline}} as the \code{min.L} parameter. Default is 1.
#' @param streamline_res A numeric value specifying the resolution of the streamline integration. Passed to \code{\link[metR]{geom_streamline}} as the \code{res} parameter. Default is 1.
#' @param streamline_n A numeric value specifying the number of streamlines to draw. Passed to \code{\link[metR]{geom_streamline}} as the \code{n} parameter. Default is 15.
#' @param streamline_width A numeric vector of length 2 specifying the range of line widths for streamlines. Passed to \code{scale_size(range = ...)}. Only used when \code{streamline_color} is \code{NULL}. Default is \code{c(0, 0.8)}.
#' @param streamline_width A numeric vector of length 2 specifying the range of line widths for streamlines. Passed to \code{scale_linewidth(range = ...)}. Only used when \code{streamline_color} is \code{NULL}. Default is \code{c(0, 0.8)}.
#' @param streamline_alpha A numeric value between 0 and 1 specifying the transparency of the velocity streamlines. Default is 1.
#' @param streamline_color An optional character string specifying a fixed color for streamlines. When \code{NULL} (the default), streamlines are colored by velocity magnitude using \code{streamline_palette}.
#' @param streamline_palette A character string specifying the color palette for streamline velocity magnitude. Passed to \code{\link{palette_this}}. Only used when \code{streamline_color} is \code{NULL}. Default is \code{"RdYlBu"}.
Expand Down Expand Up @@ -674,8 +674,10 @@ VelocityPlot <- function(
order = 1
)
),
# Size scale for streamline width
scale_size(range = range(streamline_width), guide = "none")
# The streamlines map `linewidth = after_stat(step)`, so the scale must be
# scale_linewidth(); scale_size() targets a different aesthetic and leaves the
# default 1-6 linewidth scale (and its "step" guide) in place.
scale_linewidth(range = range(streamline_width), guide = "none")
)
attr(velocity_layer, "scales") <- unique(c(
attr(velocity_layer, "scales"),
Expand Down
4 changes: 2 additions & 2 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package:
name: r-plotthis
version: 0.14.1
version: 0.14.2

source:
path: ..

build:
number: 2
number: 1
rpaths:
- lib/R/lib/
- lib/
Expand Down
2 changes: 1 addition & 1 deletion man/DimPlotAtomic.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/VelocityPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/dimplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions tests/testthat/test-velocityplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,33 @@ test_that("VelocityPlot with plot_type = 'stream' works", {
expect_s3_class(p, "ggplot")
})

test_that("streamline_width controls stream line thickness", {
# The stream branch maps `linewidth = after_stat(step)`; scaling `size` instead left the
# default ggplot linewidth scale in place, so every streamline rendered 1-6 wide and the
# argument did nothing. The graph has three GeomStreamline layers -- a fixed-width halo, the
# scaled streamline layer, and a fixed-width arrow layer -- so assertions target the scaled
# one (the only layer with more than one distinct linewidth).
scaled_max <- function(w) {
p <- VelocityPlot(embedding, v_embedding, plot_type = "stream",
streamline_width = w)
expect_true(any(vapply(p$scales$scales,
function(s) "linewidth" %in% s$aesthetics, logical(1))))
expect_false(any(vapply(p$scales$scales,
function(s) "size" %in% s$aesthetics, logical(1))))
lws <- lapply(ggplot2::ggplot_build(p)$data, function(d) {
if ("linewidth" %in% names(d)) unique(d$linewidth) else numeric()
})
scaled <- Filter(function(v) length(v) > 1, lws)
expect_length(scaled, 1L)
max(scaled[[1]])
}
thin <- scaled_max(c(0, 0.2))
thick <- scaled_max(c(0, 0.8))
expect_lte(thin, 0.2)
expect_lte(thick, 0.8)
expect_lt(thin, thick)
})

test_that("VelocityPlot with title and subtitle works", {
p <- VelocityPlot(embedding, v_embedding, plot_type = "raw",
title = "Velocity Title", subtitle = "Subtitle")
Expand Down
Loading