From 9149657f65e0dd25bfa80c83a2d0bee8e3de4fa6 Mon Sep 17 00:00:00 2001 From: Achim Zeileis Date: Sun, 7 Jun 2026 05:41:38 +0200 Subject: [PATCH 01/14] added tinyplot.data.frame method --- NAMESPACE | 1 + R/tinyplot.data.frame.R | 58 ++++++++++++++++++++++++++++++++++++++ man/tinyplot.data.frame.Rd | 49 ++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 R/tinyplot.data.frame.R create mode 100644 man/tinyplot.data.frame.Rd diff --git a/NAMESPACE b/NAMESPACE index 2f9d179e..ea5b1a5c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +S3method(tinyplot,data.frame) S3method(tinyplot,default) S3method(tinyplot,density) S3method(tinyplot,formula) diff --git a/R/tinyplot.data.frame.R b/R/tinyplot.data.frame.R new file mode 100644 index 00000000..d01365c4 --- /dev/null +++ b/R/tinyplot.data.frame.R @@ -0,0 +1,58 @@ +#' tinyplot Method for Plotting Data Frames +#' +#' @description Convenience interface for visualizing data.frame objects +#' with tinyplot. +#' +#' @details This is a convenience function for plotting data frames with +#' or without a formula. The case with the formula mainly facilitates +#' using `tinyplot()` in combination with pipes. The case without +#' formula provides a quick way of plotting the variables in data frames, +#' either only one variable or a pair of variables. In the future, the +#' latter might be extended to a pairs display for data frames with +#' more than two variables but this is not implemented, yet. See the +#' examples for illustrations. +#' +#' @param x an object of class `"data.frame"`. +#' @param formula a \code{\link[stats]{formula}} that is passed on to +#' \code{\link{tinyplot.formula}}. If `formula` is `NULL` a formula of +#' type `y ~ 1` or `y ~ x` is set up for 1- and 2-dimensional data frames, +#' respectively. For data frames with more than 2 variables the `facet = NULL` +#' case is not supported, yet, and currently leads to an error. +#' @param ... further arguments passed to `tinyplot`. +#' +#' @examples +#' tinytheme("clean2") +#' +#' ## using tinyplot() with data frames and pipes +#' cars |> tinyplot() +#' iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) +#' +#' ## tinyplot(df) only works for data frames with 1 or 2 variables +#' ## in the future we might add a pairs-style display as follows +#' ## but this would require better handling of axes and their labels +#' par(mfrow = c(5, 5)) +#' for (i in names(iris)) for(j in names(iris)) tinyplot(iris[, unique(c(j, i)), drop = FALSE]) +#' +#' tinytheme() ## reset +#' +#' @export +tinyplot.data.frame = function (x, formula = NULL, ...) { + ## original call + cl = match.call() + + ## default formula + ## 1d: y ~ 1 + ## 2d: y ~ x + ## 3d: pairs? (not supported, yet) + if (is.null(formula)) { + if (ncol(x) > 2L) stop("'formula' is missing with no default for more than 2 columns") + f = names(x) + if (length(f) < 2L) f = c("1", f) + cl$formula = as.formula(paste(f[2L:1L], collapse = " ~ ")) + } + + ## evaluate updated call + names(cl)[names(cl) == "x"] = "data" + cl[[1L]] = quote(tinyplot::tinyplot) + eval.parent(cl) +} diff --git a/man/tinyplot.data.frame.Rd b/man/tinyplot.data.frame.Rd new file mode 100644 index 00000000..9b0ecbdb --- /dev/null +++ b/man/tinyplot.data.frame.Rd @@ -0,0 +1,49 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tinyplot.data.frame.R +\name{tinyplot.data.frame} +\alias{tinyplot.data.frame} +\title{tinyplot Method for Plotting Data Frames} +\usage{ +\method{tinyplot}{data.frame}(x, formula = NULL, ...) +} +\arguments{ +\item{x}{an object of class \code{"data.frame"}.} + +\item{formula}{a \code{\link[stats]{formula}} that is passed on to +\code{\link{tinyplot.formula}}. If \code{formula} is \code{NULL} a formula of +type \code{y ~ 1} or \code{y ~ x} is set up for 1- and 2-dimensional data frames, +respectively. For data frames with more than 2 variables the \code{facet = NULL} +case is not supported, yet, and currently leads to an error.} + +\item{...}{further arguments passed to \code{tinyplot}.} +} +\description{ +Convenience interface for visualizing data.frame objects +with tinyplot. +} +\details{ +This is a convenience function for plotting data frames with +or without a formula. The case with the formula mainly facilitates +using \code{tinyplot()} in combination with pipes. The case without +formula provides a quick way of plotting the variables in data frames, +either only one variable or a pair of variables. In the future, the +latter might be extended to a pairs display for data frames with +more than two variables but this is not implemented, yet. See the +examples for illustrations. +} +\examples{ +tinytheme("clean2") + +## using tinyplot() with data frames and pipes +cars |> tinyplot() +iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) + +## tinyplot(df) only works for data frames with 1 or 2 variables +## in the future we might add a pairs-style display as follows +## but this would require better handling of axes and their labels +par(mfrow = c(5, 5)) +for (i in names(iris)) for(j in names(iris)) tinyplot(iris[, unique(c(j, i)), drop = FALSE]) + +tinytheme() ## reset + +} From 145c6455940d17e767779ece0f66d12469cece55 Mon Sep 17 00:00:00 2001 From: Achim Zeileis Date: Thu, 18 Jun 2026 03:15:36 +0200 Subject: [PATCH 02/14] pairs-esque display in data.frame method for 3 or more variables --- NAMESPACE | 1 + R/tinyplot.data.frame.R | 81 ++++++++++++++++++++++++++++------------- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index ea5b1a5c..2d2e56a6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -130,6 +130,7 @@ importFrom(stats,qchisq) importFrom(stats,qnorm) importFrom(stats,qt) importFrom(stats,quantile) +importFrom(stats,reformulate) importFrom(stats,setNames) importFrom(stats,spline) importFrom(stats,terms) diff --git a/R/tinyplot.data.frame.R b/R/tinyplot.data.frame.R index d01365c4..b35f45e8 100644 --- a/R/tinyplot.data.frame.R +++ b/R/tinyplot.data.frame.R @@ -7,10 +7,8 @@ #' or without a formula. The case with the formula mainly facilitates #' using `tinyplot()` in combination with pipes. The case without #' formula provides a quick way of plotting the variables in data frames, -#' either only one variable or a pair of variables. In the future, the -#' latter might be extended to a pairs display for data frames with -#' more than two variables but this is not implemented, yet. See the -#' examples for illustrations. +#' either only one variable or a pair of variables, or all possible pairs +#' of variables. #' #' @param x an object of class `"data.frame"`. #' @param formula a \code{\link[stats]{formula}} that is passed on to @@ -23,36 +21,69 @@ #' @examples #' tinytheme("clean2") #' -#' ## using tinyplot() with data frames and pipes -#' cars |> tinyplot() -#' iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) +#' ## using tinyplot() with data frames +#' tinyplot(cars) +#' tinyplot(iris, Sepal.Length ~ Petal.Width | Species) #' -#' ## tinyplot(df) only works for data frames with 1 or 2 variables -#' ## in the future we might add a pairs-style display as follows -#' ## but this would require better handling of axes and their labels -#' par(mfrow = c(5, 5)) -#' for (i in names(iris)) for(j in names(iris)) tinyplot(iris[, unique(c(j, i)), drop = FALSE]) +#' ## note that this also enables usage with pipes (in R >= 4.1.0) such as +#' ## cars |> tinyplot() +#' ## iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) +#' +#' ## pairs-style display for more than 2 variables +#' ## (handling of axes and their labels will be improved in future versions) +#' tinyplot(iris) #' #' tinytheme() ## reset #' +#' @importFrom stats reformulate #' @export tinyplot.data.frame = function (x, formula = NULL, ...) { ## original call cl = match.call() - ## default formula - ## 1d: y ~ 1 - ## 2d: y ~ x - ## 3d: pairs? (not supported, yet) - if (is.null(formula)) { - if (ncol(x) > 2L) stop("'formula' is missing with no default for more than 2 columns") - f = names(x) - if (length(f) < 2L) f = c("1", f) - cl$formula = as.formula(paste(f[2L:1L], collapse = " ~ ")) - } - - ## evaluate updated call + ## update call for formula interface names(cl)[names(cl) == "x"] = "data" cl[[1L]] = quote(tinyplot::tinyplot) - eval.parent(cl) + if (is.null(formula)) cl$formula = . ~ . + id = which(names(cl) == "formula") + cl = as.call(as.list(cl)[c(1L, id, setdiff(2L:length(cl), id))]) + + ## variables + nm = names(x) + n = length(nm) + + if (is.null(formula) & n > 2L) { + + ## 3d: pairs-esque + op = par(mfrow = c(n, n)) + for (j in 1L:n) { + for (i in 1L:n) { + cl_ij = cl + if (i == j) { + cl_ij$formula = reformulate("1", nm[i]) + cl_ij$xlab = "" + cl_ij$ylab = "" + cl_ij$main = nm[i] + } else { + cl_ij$formula = reformulate(nm[i], nm[j]) + if (i > 1L) cl_ij$ylab = "" + if (j < n) cl_ij$xlab = "" + } + eval.parent(cl_ij) + } + } + par(op) + + } else { + + ## default formula + ## 1d: y ~ 1 + ## 2d: y ~ x + if (is.null(formula)) { + cl$formula = if (length(nm) < 2L) reformulate("1", nm) else reformulate(nm[1L], nm[2L]) + } + + ## evaluate updated call + eval.parent(cl) + } } From f4fb5982f5daf284fce4afe2c75a1b27323d3405 Mon Sep 17 00:00:00 2001 From: Achim Zeileis Date: Thu, 18 Jun 2026 03:16:06 +0200 Subject: [PATCH 03/14] avoid using |> in examples --- man/tinyplot.data.frame.Rd | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/man/tinyplot.data.frame.Rd b/man/tinyplot.data.frame.Rd index 9b0ecbdb..63672c64 100644 --- a/man/tinyplot.data.frame.Rd +++ b/man/tinyplot.data.frame.Rd @@ -26,23 +26,23 @@ This is a convenience function for plotting data frames with or without a formula. The case with the formula mainly facilitates using \code{tinyplot()} in combination with pipes. The case without formula provides a quick way of plotting the variables in data frames, -either only one variable or a pair of variables. In the future, the -latter might be extended to a pairs display for data frames with -more than two variables but this is not implemented, yet. See the -examples for illustrations. +either only one variable or a pair of variables, or all possible pairs +of variables. } \examples{ tinytheme("clean2") -## using tinyplot() with data frames and pipes -cars |> tinyplot() -iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) +## using tinyplot() with data frames +tinyplot(cars) +tinyplot(iris, Sepal.Length ~ Petal.Width | Species) -## tinyplot(df) only works for data frames with 1 or 2 variables -## in the future we might add a pairs-style display as follows -## but this would require better handling of axes and their labels -par(mfrow = c(5, 5)) -for (i in names(iris)) for(j in names(iris)) tinyplot(iris[, unique(c(j, i)), drop = FALSE]) +## note that this also enables usage with pipes (in R >= 4.1.0) such as +## cars |> tinyplot() +## iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) + +## pairs-style display for more than 2 variables +## (handling of axes and their labels will be improved in future versions) +tinyplot(iris) tinytheme() ## reset From 13cf43863b64c5b5ed4508167a1b808b246aeb2e Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Fri, 19 Jun 2026 12:55:20 -0700 Subject: [PATCH 04/14] tweaks --- R/tinyplot.data.frame.R | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/R/tinyplot.data.frame.R b/R/tinyplot.data.frame.R index b35f45e8..a4c23d2e 100644 --- a/R/tinyplot.data.frame.R +++ b/R/tinyplot.data.frame.R @@ -54,25 +54,53 @@ tinyplot.data.frame = function (x, formula = NULL, ...) { if (is.null(formula) & n > 2L) { - ## 3d: pairs-esque + ## 3d: pairs-esque op = par(mfrow = c(n, n)) + on.exit(par(op)) + + ## We'll (manually) scale cex elements similar to faceted plots. + ## Safest way is to capture the existing theme and then inject temporary + ## overrides via an ephemeral theme. The theme is built as a language object + ## because `cl` is a matched call, so `cl[["theme"]]` is unevaluated (e.g. + ## the call `list("dark")`, not a list). + cex_fct_adj = 0.66 # use same scaling as with faceted plots. + active_theme = get_tpar("tinytheme", default = "default") + theme_arg = cl[["theme"]] + if (is.null(theme_arg)) { + theme_ij = bquote(list(.(active_theme), cex = .(cex_fct_adj))) + } else if (is.call(theme_arg) && identical(theme_arg[[1L]], as.name("list"))) { + theme_arg[["cex"]] = cex_fct_adj + theme_ij = theme_arg + } else { + theme_ij = bquote(list(.(theme_arg), cex = .(cex_fct_adj))) + } + + ## Ephemeral themes revert to the *default* theme on exit, so after the loop + ## we must re-assert any persistent theme that was active beforehand. + if (!identical(active_theme, "default")) { + on.exit(tinytheme(active_theme), add = TRUE) + } + for (j in 1L:n) { for (i in 1L:n) { cl_ij = cl + cl_ij[["theme"]] = theme_ij if (i == j) { cl_ij$formula = reformulate("1", nm[i]) - cl_ij$xlab = "" - cl_ij$ylab = "" + # cl_ij$xlab = "" + # cl_ij$ylab = "" cl_ij$main = nm[i] } else { cl_ij$formula = reformulate(nm[i], nm[j]) - if (i > 1L) cl_ij$ylab = "" - if (j < n) cl_ij$xlab = "" + # if (i > 1L) cl_ij$ylab = "" + # if (j < n) cl_ij$xlab = "" } + cl_ij$ylab = NA + cl_ij$xlab = NA eval.parent(cl_ij) + box("figure", lwd = 0.5) } } - par(op) } else { From f59bfa5fa32f53470bba43b90dbdff75c8b5bea6 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Fri, 19 Jun 2026 16:25:31 -0700 Subject: [PATCH 05/14] tweaks --- R/tinyplot.data.frame.R | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/R/tinyplot.data.frame.R b/R/tinyplot.data.frame.R index a4c23d2e..b5e262b7 100644 --- a/R/tinyplot.data.frame.R +++ b/R/tinyplot.data.frame.R @@ -87,18 +87,20 @@ tinyplot.data.frame = function (x, formula = NULL, ...) { cl_ij[["theme"]] = theme_ij if (i == j) { cl_ij$formula = reformulate("1", nm[i]) - # cl_ij$xlab = "" - # cl_ij$ylab = "" + # cl_ij$xlab = NA + # cl_ij$ylab = NA cl_ij$main = nm[i] } else { cl_ij$formula = reformulate(nm[i], nm[j]) - # if (i > 1L) cl_ij$ylab = "" - # if (j < n) cl_ij$xlab = "" + # if (i > 1L) cl_ij$ylab = NA + # if (j < n) cl_ij$xlab = NA } + # GM: drop all axes labs (like pairs) cl_ij$ylab = NA cl_ij$xlab = NA eval.parent(cl_ij) - box("figure", lwd = 0.5) + # GM: add box around each plot + box("figure", lwd = 0.3) } } From d3bdef4686640cca97f8b3717bbf6f7c5cc41e4f Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Fri, 19 Jun 2026 22:13:14 -0700 Subject: [PATCH 06/14] add frames and labs args and tidy doc language --- R/tinyplot.data.frame.R | 36 ++++++++++++++++++++---------------- man/tinyplot.data.frame.Rd | 19 +++++++++++++------ 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/R/tinyplot.data.frame.R b/R/tinyplot.data.frame.R index b5e262b7..0e44e66b 100644 --- a/R/tinyplot.data.frame.R +++ b/R/tinyplot.data.frame.R @@ -13,9 +13,15 @@ #' @param x an object of class `"data.frame"`. #' @param formula a \code{\link[stats]{formula}} that is passed on to #' \code{\link{tinyplot.formula}}. If `formula` is `NULL` a formula of -#' type `y ~ 1` or `y ~ x` is set up for 1- and 2-dimensional data frames, -#' respectively. For data frames with more than 2 variables the `facet = NULL` -#' case is not supported, yet, and currently leads to an error. +#' type `y ~ 1` or `y ~ x` is set up for 1- and 2-variable data frames, +#' respectively. For data frames with 3 or more variables, a +#' \code{\link[graphics]{pairs}}-style grid of all variable combinations is +#' drawn instead. +#' @param labs logical indicating whether the axes labels (titles) for each +#' sub-plot in the >=3 case should be shown. Default is `FALSE`. +#' @param frames logical indicating whether each sub-plot in the >=3 case should +#' be framed by a box. Default is `TRUE`. Note the trailing "s" plural case to +#' disambiguate from `frame.plot`. #' @param ... further arguments passed to `tinyplot`. #' #' @examples @@ -29,15 +35,14 @@ #' ## cars |> tinyplot() #' ## iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) #' -#' ## pairs-style display for more than 2 variables -#' ## (handling of axes and their labels will be improved in future versions) +#' ## pairs-style display data frames for more than 2 variables #' tinyplot(iris) #' #' tinytheme() ## reset #' #' @importFrom stats reformulate #' @export -tinyplot.data.frame = function (x, formula = NULL, ...) { +tinyplot.data.frame = function (x, formula = NULL, labs = FALSE, frames = TRUE, ...) { ## original call cl = match.call() @@ -52,12 +57,15 @@ tinyplot.data.frame = function (x, formula = NULL, ...) { nm = names(x) n = length(nm) - if (is.null(formula) & n > 2L) { + if (is.null(formula) && n > 2L) { ## 3d: pairs-esque op = par(mfrow = c(n, n)) on.exit(par(op)) + assert_logical(labs) + assert_logical(frames) + ## We'll (manually) scale cex elements similar to faceted plots. ## Safest way is to capture the existing theme and then inject temporary ## overrides via an ephemeral theme. The theme is built as a language object @@ -87,20 +95,16 @@ tinyplot.data.frame = function (x, formula = NULL, ...) { cl_ij[["theme"]] = theme_ij if (i == j) { cl_ij$formula = reformulate("1", nm[i]) - # cl_ij$xlab = NA - # cl_ij$ylab = NA cl_ij$main = nm[i] } else { cl_ij$formula = reformulate(nm[i], nm[j]) - # if (i > 1L) cl_ij$ylab = NA - # if (j < n) cl_ij$xlab = NA } - # GM: drop all axes labs (like pairs) - cl_ij$ylab = NA - cl_ij$xlab = NA + if (!labs) { + cl_ij$ylab = NA + cl_ij$xlab = NA + } eval.parent(cl_ij) - # GM: add box around each plot - box("figure", lwd = 0.3) + if (frames) box("figure", lwd = 0.3) } } diff --git a/man/tinyplot.data.frame.Rd b/man/tinyplot.data.frame.Rd index 63672c64..8914c05a 100644 --- a/man/tinyplot.data.frame.Rd +++ b/man/tinyplot.data.frame.Rd @@ -4,16 +4,24 @@ \alias{tinyplot.data.frame} \title{tinyplot Method for Plotting Data Frames} \usage{ -\method{tinyplot}{data.frame}(x, formula = NULL, ...) +\method{tinyplot}{data.frame}(x, formula = NULL, labs = FALSE, frames = TRUE, ...) } \arguments{ \item{x}{an object of class \code{"data.frame"}.} \item{formula}{a \code{\link[stats]{formula}} that is passed on to \code{\link{tinyplot.formula}}. If \code{formula} is \code{NULL} a formula of -type \code{y ~ 1} or \code{y ~ x} is set up for 1- and 2-dimensional data frames, -respectively. For data frames with more than 2 variables the \code{facet = NULL} -case is not supported, yet, and currently leads to an error.} +type \code{y ~ 1} or \code{y ~ x} is set up for 1- and 2-variable data frames, +respectively. For data frames with 3 or more variables, a +\code{\link[graphics]{pairs}}-style grid of all variable combinations is +drawn instead.} + +\item{labs}{logical indicating whether the axes labels (titles) for each +sub-plot in the >=3 case should be shown. Default is \code{FALSE}.} + +\item{frames}{logical indicating whether each sub-plot in the >=3 case should +be framed by a box. Default is \code{TRUE}. Note the trailing "s" plural case to +disambiguate from \code{frame.plot}.} \item{...}{further arguments passed to \code{tinyplot}.} } @@ -40,8 +48,7 @@ tinyplot(iris, Sepal.Length ~ Petal.Width | Species) ## cars |> tinyplot() ## iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) -## pairs-style display for more than 2 variables -## (handling of axes and their labels will be improved in future versions) +## pairs-style display data frames for more than 2 variables tinyplot(iris) tinytheme() ## reset From 1be757305c879132acdd28fde31ebcb21d5a111c Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Fri, 19 Jun 2026 22:15:24 -0700 Subject: [PATCH 07/14] backticks gotcha for non-syntactic names --- R/tinyplot.data.frame.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/tinyplot.data.frame.R b/R/tinyplot.data.frame.R index 0e44e66b..6851c9ba 100644 --- a/R/tinyplot.data.frame.R +++ b/R/tinyplot.data.frame.R @@ -57,6 +57,10 @@ tinyplot.data.frame = function (x, formula = NULL, labs = FALSE, frames = TRUE, nm = names(x) n = length(nm) + ## backtick-protect names so reformulate() parses non-syntactic names (e.g. + ## "GDP (2020)") as single symbols rather than as code, matching pairs(). + bt = function(x) paste0("`", x, "`") + if (is.null(formula) && n > 2L) { ## 3d: pairs-esque @@ -94,10 +98,10 @@ tinyplot.data.frame = function (x, formula = NULL, labs = FALSE, frames = TRUE, cl_ij = cl cl_ij[["theme"]] = theme_ij if (i == j) { - cl_ij$formula = reformulate("1", nm[i]) + cl_ij$formula = reformulate("1", bt(nm[i])) cl_ij$main = nm[i] } else { - cl_ij$formula = reformulate(nm[i], nm[j]) + cl_ij$formula = reformulate(bt(nm[i]), bt(nm[j])) } if (!labs) { cl_ij$ylab = NA @@ -114,7 +118,7 @@ tinyplot.data.frame = function (x, formula = NULL, labs = FALSE, frames = TRUE, ## 1d: y ~ 1 ## 2d: y ~ x if (is.null(formula)) { - cl$formula = if (length(nm) < 2L) reformulate("1", nm) else reformulate(nm[1L], nm[2L]) + cl$formula = if (length(nm) < 2L) reformulate("1", bt(nm)) else reformulate(bt(nm[1L]), bt(nm[2L])) } ## evaluate updated call From 7f70e27532228dcf0a42dd7972a4dbd7fb7e15ba Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Fri, 19 Jun 2026 22:33:09 -0700 Subject: [PATCH 08/14] slightly faster --- R/tinyplot.data.frame.R | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/R/tinyplot.data.frame.R b/R/tinyplot.data.frame.R index 6851c9ba..b3ad4bbf 100644 --- a/R/tinyplot.data.frame.R +++ b/R/tinyplot.data.frame.R @@ -70,11 +70,10 @@ tinyplot.data.frame = function (x, formula = NULL, labs = FALSE, frames = TRUE, assert_logical(labs) assert_logical(frames) - ## We'll (manually) scale cex elements similar to faceted plots. - ## Safest way is to capture the existing theme and then inject temporary - ## overrides via an ephemeral theme. The theme is built as a language object - ## because `cl` is a matched call, so `cl[["theme"]]` is unevaluated (e.g. - ## the call `list("dark")`, not a list). + ## To scale cex like faceted plots, we capture the existing theme and apply + ## temporary cex overrides (restoring on exit). The theme is built as a + ## language object because `cl` is a matched call, so `cl[["theme"]]` is + ## unevaluated (e.g. the call `list("dark")`, not a list). cex_fct_adj = 0.66 # use same scaling as with faceted plots. active_theme = get_tpar("tinytheme", default = "default") theme_arg = cl[["theme"]] @@ -86,17 +85,18 @@ tinyplot.data.frame = function (x, formula = NULL, labs = FALSE, frames = TRUE, } else { theme_ij = bquote(list(.(theme_arg), cex = .(cex_fct_adj))) } + ## drop any `theme` from the cell call so it isn't re-applied per cell (see + ## above). NULL-assignment on a call errors if the element is absent, so + ## guard with a membership check. + if ("theme" %in% names(cl)) cl[["theme"]] = NULL - ## Ephemeral themes revert to the *default* theme on exit, so after the loop - ## we must re-assert any persistent theme that was active beforehand. - if (!identical(active_theme, "default")) { - on.exit(tinytheme(active_theme), add = TRUE) - } + ## apply temp theme overrides and restore orig theme on exit + do.call(tinytheme, eval(theme_ij)) + on.exit(if (identical(active_theme, "default")) tinytheme() else tinytheme(active_theme), add = TRUE) for (j in 1L:n) { for (i in 1L:n) { cl_ij = cl - cl_ij[["theme"]] = theme_ij if (i == j) { cl_ij$formula = reformulate("1", bt(nm[i])) cl_ij$main = nm[i] From f6cf8800a34dacbede37c3b47b1b2cd02aca4267 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Fri, 19 Jun 2026 22:49:40 -0700 Subject: [PATCH 09/14] support `by` arg --- R/tinyplot.data.frame.R | 54 +++++++++++++++++++++++++++----------- man/tinyplot.data.frame.Rd | 33 ++++++++++++++--------- 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/R/tinyplot.data.frame.R b/R/tinyplot.data.frame.R index b3ad4bbf..eab68f09 100644 --- a/R/tinyplot.data.frame.R +++ b/R/tinyplot.data.frame.R @@ -6,23 +6,28 @@ #' @details This is a convenience function for plotting data frames with #' or without a formula. The case with the formula mainly facilitates #' using `tinyplot()` in combination with pipes. The case without -#' formula provides a quick way of plotting the variables in data frames, -#' either only one variable or a pair of variables, or all possible pairs -#' of variables. +#' formula provides a quick way of plotting the variables in a data frame: +#' a single variable, a pair of variables, or a +#' \code{\link[graphics]{pairs}}-style grid of all variable combinations for +#' 3 or more variables. #' #' @param x an object of class `"data.frame"`. #' @param formula a \code{\link[stats]{formula}} that is passed on to #' \code{\link{tinyplot.formula}}. If `formula` is `NULL` a formula of #' type `y ~ 1` or `y ~ x` is set up for 1- and 2-variable data frames, -#' respectively. For data frames with 3 or more variables, a -#' \code{\link[graphics]{pairs}}-style grid of all variable combinations is -#' drawn instead. +#' respectively. For data frames with 3 or more variables, a pairs-style +#' grid of all variable combinations is drawn instead. +#' @param by optional string giving the name of a column in `x` to use as a +#' grouping variable in the pairs-style case. The variable is spliced into +#' each sub-plot's formula as `y ~ x | by` so groups are distinguished (e.g. +#' by colour). A legend is suppressed in this case to avoid repeating it +#' across every sub-plot. Ignored for 1- and 2-variable data frames. #' @param labs logical indicating whether the axes labels (titles) for each -#' sub-plot in the >=3 case should be shown. Default is `FALSE`. -#' @param frames logical indicating whether each sub-plot in the >=3 case should -#' be framed by a box. Default is `TRUE`. Note the trailing "s" plural case to -#' disambiguate from `frame.plot`. -#' @param ... further arguments passed to `tinyplot`. +#' sub-plot in the pairs-style case should be shown. Default is `FALSE`. +#' @param frames logical indicating whether each sub-plot in the pairs-style +#' case should be framed by a box. Default is `TRUE`. Note the trailing "s" +#' plural case to disambiguate from `frame.plot`. +#' @param ... further arguments passed to `tinyplot`. #' #' @examples #' tinytheme("clean2") @@ -35,14 +40,17 @@ #' ## cars |> tinyplot() #' ## iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) #' -#' ## pairs-style display data frames for more than 2 variables +#' ## pairs-style display for data frames with 3 or more variables #' tinyplot(iris) #' +#' ## use `by` to group the pairs-style display (legend is suppressed) +#' tinyplot(iris, by = "Species") +#' #' tinytheme() ## reset #' #' @importFrom stats reformulate #' @export -tinyplot.data.frame = function (x, formula = NULL, labs = FALSE, frames = TRUE, ...) { +tinyplot.data.frame = function (x, formula = NULL, by = NULL, labs = FALSE, frames = TRUE, ...) { ## original call cl = match.call() @@ -69,6 +77,17 @@ tinyplot.data.frame = function (x, formula = NULL, labs = FALSE, frames = TRUE, assert_logical(labs) assert_logical(frames) + assert_string(by, null.ok = TRUE) + if (!is.null(by)) assert_choice(by, nm) + + ## `by` (a column name) is spliced into each cell formula as a grouping + ## term, `y ~ x | by`. Forcing legend = FALSE avoids drawing a legend in + ## every one of the n^2 cells. Drop both from the cell call so they aren't + ## passed through verbatim. + if (!is.null(by)) { + if ("by" %in% names(cl)) cl[["by"]] = NULL + cl[["legend"]] = FALSE + } ## To scale cex like faceted plots, we capture the existing theme and apply ## temporary cex overrides (restoring on exit). The theme is built as a @@ -97,11 +116,12 @@ tinyplot.data.frame = function (x, formula = NULL, labs = FALSE, frames = TRUE, for (j in 1L:n) { for (i in 1L:n) { cl_ij = cl + grp = if (is.null(by)) "" else paste(" |", bt(by)) if (i == j) { - cl_ij$formula = reformulate("1", bt(nm[i])) + cl_ij$formula = reformulate(paste0("1", grp), bt(nm[i])) cl_ij$main = nm[i] } else { - cl_ij$formula = reformulate(bt(nm[i]), bt(nm[j])) + cl_ij$formula = reformulate(paste0(bt(nm[i]), grp), bt(nm[j])) } if (!labs) { cl_ij$ylab = NA @@ -114,6 +134,10 @@ tinyplot.data.frame = function (x, formula = NULL, labs = FALSE, frames = TRUE, } else { + ## `by` only applies to the >=3 (pairs-style) case; drop it so it isn't + ## passed through to tinyplot() here. + if ("by" %in% names(cl)) cl[["by"]] = NULL + ## default formula ## 1d: y ~ 1 ## 2d: y ~ x diff --git a/man/tinyplot.data.frame.Rd b/man/tinyplot.data.frame.Rd index 8914c05a..afd6f18d 100644 --- a/man/tinyplot.data.frame.Rd +++ b/man/tinyplot.data.frame.Rd @@ -4,7 +4,7 @@ \alias{tinyplot.data.frame} \title{tinyplot Method for Plotting Data Frames} \usage{ -\method{tinyplot}{data.frame}(x, formula = NULL, labs = FALSE, frames = TRUE, ...) +\method{tinyplot}{data.frame}(x, formula = NULL, by = NULL, labs = FALSE, frames = TRUE, ...) } \arguments{ \item{x}{an object of class \code{"data.frame"}.} @@ -12,16 +12,21 @@ \item{formula}{a \code{\link[stats]{formula}} that is passed on to \code{\link{tinyplot.formula}}. If \code{formula} is \code{NULL} a formula of type \code{y ~ 1} or \code{y ~ x} is set up for 1- and 2-variable data frames, -respectively. For data frames with 3 or more variables, a -\code{\link[graphics]{pairs}}-style grid of all variable combinations is -drawn instead.} +respectively. For data frames with 3 or more variables, a pairs-style +grid of all variable combinations is drawn instead.} + +\item{by}{optional string giving the name of a column in \code{x} to use as a +grouping variable in the pairs-style case. The variable is spliced into +each sub-plot's formula as \code{y ~ x | by} so groups are distinguished (e.g. +by colour). A legend is suppressed in this case to avoid repeating it +across every sub-plot. Ignored for 1- and 2-variable data frames.} \item{labs}{logical indicating whether the axes labels (titles) for each -sub-plot in the >=3 case should be shown. Default is \code{FALSE}.} +sub-plot in the pairs-style case should be shown. Default is \code{FALSE}.} -\item{frames}{logical indicating whether each sub-plot in the >=3 case should -be framed by a box. Default is \code{TRUE}. Note the trailing "s" plural case to -disambiguate from \code{frame.plot}.} +\item{frames}{logical indicating whether each sub-plot in the pairs-style +case should be framed by a box. Default is \code{TRUE}. Note the trailing "s" +plural case to disambiguate from \code{frame.plot}.} \item{...}{further arguments passed to \code{tinyplot}.} } @@ -33,9 +38,10 @@ with tinyplot. This is a convenience function for plotting data frames with or without a formula. The case with the formula mainly facilitates using \code{tinyplot()} in combination with pipes. The case without -formula provides a quick way of plotting the variables in data frames, -either only one variable or a pair of variables, or all possible pairs -of variables. +formula provides a quick way of plotting the variables in a data frame: +a single variable, a pair of variables, or a +\code{\link[graphics]{pairs}}-style grid of all variable combinations for +3 or more variables. } \examples{ tinytheme("clean2") @@ -48,9 +54,12 @@ tinyplot(iris, Sepal.Length ~ Petal.Width | Species) ## cars |> tinyplot() ## iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) -## pairs-style display data frames for more than 2 variables +## pairs-style display for data frames with 3 or more variables tinyplot(iris) +## use `by` to group the pairs-style display (legend is suppressed) +tinyplot(iris, by = "Species") + tinytheme() ## reset } From 87dd0d8b9b8902fb36a7302d84552eafa4831ec7 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Sat, 20 Jun 2026 09:40:18 -0700 Subject: [PATCH 10/14] frames FALSE and document --- R/tinyplot.data.frame.R | 42 ++++++++++++++++++++------------------ man/tinyplot.data.frame.Rd | 42 ++++++++++++++++++++------------------ 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/R/tinyplot.data.frame.R b/R/tinyplot.data.frame.R index eab68f09..f74411e2 100644 --- a/R/tinyplot.data.frame.R +++ b/R/tinyplot.data.frame.R @@ -1,7 +1,7 @@ #' tinyplot Method for Plotting Data Frames #' -#' @description Convenience interface for visualizing data.frame objects -#' with tinyplot. +#' @description Convenience interface for visualizing +#' \code{\link[base]{data.frames}} with tinyplot. #' #' @details This is a convenience function for plotting data frames with #' or without a formula. The case with the formula mainly facilitates @@ -15,18 +15,19 @@ #' @param formula a \code{\link[stats]{formula}} that is passed on to #' \code{\link{tinyplot.formula}}. If `formula` is `NULL` a formula of #' type `y ~ 1` or `y ~ x` is set up for 1- and 2-variable data frames, -#' respectively. For data frames with 3 or more variables, a pairs-style -#' grid of all variable combinations is drawn instead. -#' @param by optional string giving the name of a column in `x` to use as a -#' grouping variable in the pairs-style case. The variable is spliced into -#' each sub-plot's formula as `y ~ x | by` so groups are distinguished (e.g. -#' by colour). A legend is suppressed in this case to avoid repeating it -#' across every sub-plot. Ignored for 1- and 2-variable data frames. -#' @param labs logical indicating whether the axes labels (titles) for each -#' sub-plot in the pairs-style case should be shown. Default is `FALSE`. -#' @param frames logical indicating whether each sub-plot in the pairs-style -#' case should be framed by a box. Default is `TRUE`. Note the trailing "s" -#' plural case to disambiguate from `frame.plot`. +#' respectively. For data frames with 3+ variables, a +#' \code{\link[graphics]{pairs}}-style grid of all variable combinations is +#' drawn instead. +#' @param by (3+ case only) optional string giving the name of a column in `x` +#' to use as a grouping variable. The variable is spliced into each sub-plot's +#' formula as `y ~ x | by` so groups are distinguished (e.g. by colour). The +#' legend is suppressed automatically. +#' @param labs (3+ case only) logical indicating whether the axes labels +#' (titles) for each sub-plot in the pairs-style case should be shown. Default +#' is `FALSE`. +#' @param frames (3+ case only) logical indicating whether each sub-plot should +#' be framed by a box. Default is `FALSE`. Note the trailing "s" plural case +#' to disambiguate from `frame.plot`. #' @param ... further arguments passed to `tinyplot`. #' #' @examples @@ -37,20 +38,21 @@ #' tinyplot(iris, Sepal.Length ~ Petal.Width | Species) #' #' ## note that this also enables usage with pipes (in R >= 4.1.0) such as -#' ## cars |> tinyplot() -#' ## iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) +#' # cars |> tinyplot() +#' # iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) #' #' ## pairs-style display for data frames with 3 or more variables #' tinyplot(iris) #' -#' ## use `by` to group the pairs-style display (legend is suppressed) -#' tinyplot(iris, by = "Species") +#' ## pass `by` arg to group the pairs display (legend is suppressed) +#' ## here, we also add optional frames around the individual sub-plots +#' tinyplot(iris, by = "Species", frames = TRUE) #' -#' tinytheme() ## reset +#' tinytheme() ## reset theme #' #' @importFrom stats reformulate #' @export -tinyplot.data.frame = function (x, formula = NULL, by = NULL, labs = FALSE, frames = TRUE, ...) { +tinyplot.data.frame = function (x, formula = NULL, by = NULL, labs = FALSE, frames = FALSE, ...) { ## original call cl = match.call() diff --git a/man/tinyplot.data.frame.Rd b/man/tinyplot.data.frame.Rd index afd6f18d..710a4680 100644 --- a/man/tinyplot.data.frame.Rd +++ b/man/tinyplot.data.frame.Rd @@ -4,7 +4,7 @@ \alias{tinyplot.data.frame} \title{tinyplot Method for Plotting Data Frames} \usage{ -\method{tinyplot}{data.frame}(x, formula = NULL, by = NULL, labs = FALSE, frames = TRUE, ...) +\method{tinyplot}{data.frame}(x, formula = NULL, by = NULL, labs = FALSE, frames = FALSE, ...) } \arguments{ \item{x}{an object of class \code{"data.frame"}.} @@ -12,27 +12,28 @@ \item{formula}{a \code{\link[stats]{formula}} that is passed on to \code{\link{tinyplot.formula}}. If \code{formula} is \code{NULL} a formula of type \code{y ~ 1} or \code{y ~ x} is set up for 1- and 2-variable data frames, -respectively. For data frames with 3 or more variables, a pairs-style -grid of all variable combinations is drawn instead.} +respectively. For data frames with 3+ variables, a +\code{\link[graphics]{pairs}}-style grid of all variable combinations is +drawn instead.} -\item{by}{optional string giving the name of a column in \code{x} to use as a -grouping variable in the pairs-style case. The variable is spliced into -each sub-plot's formula as \code{y ~ x | by} so groups are distinguished (e.g. -by colour). A legend is suppressed in this case to avoid repeating it -across every sub-plot. Ignored for 1- and 2-variable data frames.} +\item{by}{(3+ case only) optional string giving the name of a column in \code{x} +to use as a grouping variable. The variable is spliced into each sub-plot's +formula as \code{y ~ x | by} so groups are distinguished (e.g. by colour). The +legend is suppressed automatically.} -\item{labs}{logical indicating whether the axes labels (titles) for each -sub-plot in the pairs-style case should be shown. Default is \code{FALSE}.} +\item{labs}{(3+ case only) logical indicating whether the axes labels +(titles) for each sub-plot in the pairs-style case should be shown. Default +is \code{FALSE}.} -\item{frames}{logical indicating whether each sub-plot in the pairs-style -case should be framed by a box. Default is \code{TRUE}. Note the trailing "s" -plural case to disambiguate from \code{frame.plot}.} +\item{frames}{(3+ case only) logical indicating whether each sub-plot should +be framed by a box. Default is \code{FALSE}. Note the trailing "s" plural case +to disambiguate from \code{frame.plot}.} \item{...}{further arguments passed to \code{tinyplot}.} } \description{ -Convenience interface for visualizing data.frame objects -with tinyplot. +Convenience interface for visualizing +\code{\link[base]{data.frames}} objects with tinyplot. } \details{ This is a convenience function for plotting data frames with @@ -51,15 +52,16 @@ tinyplot(cars) tinyplot(iris, Sepal.Length ~ Petal.Width | Species) ## note that this also enables usage with pipes (in R >= 4.1.0) such as -## cars |> tinyplot() -## iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) +# cars |> tinyplot() +# iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) ## pairs-style display for data frames with 3 or more variables tinyplot(iris) -## use `by` to group the pairs-style display (legend is suppressed) -tinyplot(iris, by = "Species") +## pass `by` arg to group the pairs display (legend is suppressed) +## here, we also add optional frames around the individual sub-plots +tinyplot(iris, by = "Species", frames = TRUE) -tinytheme() ## reset +tinytheme() ## reset theme } From 15f3b8ed793a5e7e48b3e4479c976e426a9ddd08 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Sat, 20 Jun 2026 10:28:08 -0700 Subject: [PATCH 11/14] support `by` vector input --- R/tinyplot.data.frame.R | 35 ++++++++++++++++++++++++----------- man/tinyplot.data.frame.Rd | 15 ++++++++++----- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/R/tinyplot.data.frame.R b/R/tinyplot.data.frame.R index f74411e2..791ad753 100644 --- a/R/tinyplot.data.frame.R +++ b/R/tinyplot.data.frame.R @@ -18,10 +18,12 @@ #' respectively. For data frames with 3+ variables, a #' \code{\link[graphics]{pairs}}-style grid of all variable combinations is #' drawn instead. -#' @param by (3+ case only) optional string giving the name of a column in `x` -#' to use as a grouping variable. The variable is spliced into each sub-plot's -#' formula as `y ~ x | by` so groups are distinguished (e.g. by colour). The -#' legend is suppressed automatically. +#' @param by (3+ case only) optional grouping variable. Either 1) a character +#' string giving a column name in `x`, or 2) a vector of equal length to the +#' main data.frame (_caveat emptor_: this is not checked). The variable is +#' spliced into each sub-plot's formula as `y ~ x | by` so groups are +#' distinguished (e.g. by colour). Note that the legend is deliberately +#' suppressed. #' @param labs (3+ case only) logical indicating whether the axes labels #' (titles) for each sub-plot in the pairs-style case should be shown. Default #' is `FALSE`. @@ -47,6 +49,9 @@ #' ## pass `by` arg to group the pairs display (legend is suppressed) #' ## here, we also add optional frames around the individual sub-plots #' tinyplot(iris, by = "Species", frames = TRUE) +#' +#' ## another option (but assumes objects of equal length) +#' tinyplot(iris[, 1:4], by = iris$Species, frames = TRUE) #' #' tinytheme() ## reset theme #' @@ -79,14 +84,22 @@ tinyplot.data.frame = function (x, formula = NULL, by = NULL, labs = FALSE, fram assert_logical(labs) assert_logical(frames) - assert_string(by, null.ok = TRUE) - if (!is.null(by)) assert_choice(by, nm) - - ## `by` (a column name) is spliced into each cell formula as a grouping - ## term, `y ~ x | by`. Forcing legend = FALSE avoids drawing a legend in - ## every one of the n^2 cells. Drop both from the cell call so they aren't - ## passed through verbatim. if (!is.null(by)) { + if (inherits(by, "character")) { + ## a column name already in `x` + assert_choice(by, nm) + } else { + ## a standalone vector: splice it into `x` under a unique name so the + ## formula method can reference it. make.unique() guards against an + ## existing "__by__" column. The name is added after `n` is computed, + ## so it is used for grouping only and not drawn as its own row/column. + by_nm = make.unique(c(nm, "__by__"))[n + 1L] + x[[by_nm]] = by + by = by_nm + cl[["data"]] = x + } + ## `by` is spliced directly into each cell formula below, so drop it from + ## the call. Suppress the legend to avoid repeating it across every cell. if ("by" %in% names(cl)) cl[["by"]] = NULL cl[["legend"]] = FALSE } diff --git a/man/tinyplot.data.frame.Rd b/man/tinyplot.data.frame.Rd index 710a4680..cdae00eb 100644 --- a/man/tinyplot.data.frame.Rd +++ b/man/tinyplot.data.frame.Rd @@ -16,10 +16,12 @@ respectively. For data frames with 3+ variables, a \code{\link[graphics]{pairs}}-style grid of all variable combinations is drawn instead.} -\item{by}{(3+ case only) optional string giving the name of a column in \code{x} -to use as a grouping variable. The variable is spliced into each sub-plot's -formula as \code{y ~ x | by} so groups are distinguished (e.g. by colour). The -legend is suppressed automatically.} +\item{by}{(3+ case only) optional grouping variable. Either 1) a character +string giving a column name in \code{x}, or 2) a vector of equal length to the +main data.frame (\emph{caveat emptor}: this is not checked). The variable is +spliced into each sub-plot's formula as \code{y ~ x | by} so groups are +distinguished (e.g. by colour). Note that the legend is deliberately +suppressed.} \item{labs}{(3+ case only) logical indicating whether the axes labels (titles) for each sub-plot in the pairs-style case should be shown. Default @@ -33,7 +35,7 @@ to disambiguate from \code{frame.plot}.} } \description{ Convenience interface for visualizing -\code{\link[base]{data.frames}} objects with tinyplot. +\code{\link[base]{data.frames}} with tinyplot. } \details{ This is a convenience function for plotting data frames with @@ -62,6 +64,9 @@ tinyplot(iris) ## here, we also add optional frames around the individual sub-plots tinyplot(iris, by = "Species", frames = TRUE) +## another option (but assumes objects of equal length) +tinyplot(iris[, 1:4], by = iris$Species, frames = TRUE) + tinytheme() ## reset theme } From 0709aaca6c14c1c0279ee7c2b00243a5dadb06e4 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Sat, 20 Jun 2026 10:40:24 -0700 Subject: [PATCH 12/14] news --- inst/tinytest/test-data.frame.R | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 inst/tinytest/test-data.frame.R diff --git a/inst/tinytest/test-data.frame.R b/inst/tinytest/test-data.frame.R new file mode 100644 index 00000000..b6db99d7 --- /dev/null +++ b/inst/tinytest/test-data.frame.R @@ -0,0 +1,38 @@ +source("helpers.R") +using("tinysnapshot") + +# 2-variable data frame -> y ~ x +f = function() tinyplot(cars) +expect_snapshot_plot(f, label = "df_2var") + +# 3+ variables -> pairs-style grid +f = function() tinyplot(iris) +expect_snapshot_plot(f, label = "df_pairs") + +# pairs grid with a `by` grouping variable (column name) +f = function() tinyplot(iris, by = "Species") +expect_snapshot_plot(f, label = "df_pairs_by") + +# `by` as a standalone vector (grouping var excluded from the grid) +f = function() tinyplot(iris[, 1:4], by = iris$Species) +expect_snapshot_plot(f, label = "df_pairs_by_vector") + +# axis labels and per-panel frames toggled on +f = function() tinyplot(iris, by = "Species", labs = TRUE, frames = TRUE) +expect_snapshot_plot(f, label = "df_pairs_labs_frames") + + +# Non-snapshot logical / error checks (run on any platform) ----- + +# `by` column name must exist in the data frame +expect_error(tinyplot(iris, by = "nope")) + +# non-syntactic column names work (matching pairs()) +df = iris[, 1:3] +names(df) = c("a b", "c d", "e f") +expect_silent(tinyplot(df)) + +# a pre-existing "__by__" column does not collide with the spliced vector +df = iris[, 1:4] +df[["__by__"]] = rnorm(nrow(df)) +expect_silent(tinyplot(df, by = iris$Species)) From 16fe06e7dda055c0494fe9bf82eed6f218de6a07 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Sat, 20 Jun 2026 10:41:45 -0700 Subject: [PATCH 13/14] tweak --- NEWS.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 68da48f2..454bd69a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -160,6 +160,19 @@ Theme fixes: ### Other new features +- A dedicated `tinyplot.data.frame()` method now supports direct plotting of + data frames, with or without a formula. Combining with a formula is mostly + useful insofar as it facilitates piping, e.g. + + ```r + iris |> plt(Sepal.Length ~ Petal.Width | Species) + ``` + + If no formula is provided, then the behaviour depends on the number of + variables (columns) in the data frame. For example, a dataset with 3 or more + variables will yield a `pairs()`-style grid of all variable combinations. + Thanks to @mthulin for the suggestion and original implementation idea. + (#613 @zeileis @grantmcdermott) - The `grid` argument (and `tpar("grid")`) now accepts character strings to control axis-specific grids at different resolutions. Uppercase letters (`"X"`, `"Y"`, `"XY"`) draw grid lines at the standard tick positions, while @@ -172,10 +185,9 @@ Theme fixes: customizable via `tpar()` parameters: `adj.cap`, `cex.cap`, `col.cap`, `font.cap`, and `line.cap`. (#592 @grantmcdermott) - Facet formulas now support `1` as a convenience syntax for single row or - column arrangements. For example, `plt(..., facet = z ~ 1)` is equivalent to - `plt(..., facet = ~z, facet.args = list(ncol = 1))`. Analogously, - `plt(..., facet = 1 ~ z)` can be used as a shortcut for - `plt(..., facet = ~ z, facet.args = list(nrow = 1))`. (#562 @zeileis) + column arrangements. (#562 @zeileis) + - `plt(..., facet = z ~ 1)` <-> `plt(..., facet = ~z, facet.args = list(ncol = 1))` + - `plt(..., facet = 1 ~ z)` <-> `plt(..., facet = ~z, facet.args = list(nrow = 1))`. - `type_barplot()` gains an `offset` argument for shifting bar baselines away from zero. (#611, #615 @grantmcdermott @zeileis) - If the offset is an unnamed scalar or numeric vector, it shifts the bars From fd257520e5f0db22594838e1fb06356837105f03 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Sat, 20 Jun 2026 10:46:32 -0700 Subject: [PATCH 14/14] tests --- inst/tinytest/_tinysnapshot/df_2var.svg | 114 + inst/tinytest/_tinysnapshot/df_pairs.svg | 3069 +++++++++++++++ inst/tinytest/_tinysnapshot/df_pairs_by.svg | 3236 +++++++++++++++ .../_tinysnapshot/df_pairs_by_vector.svg | 2553 ++++++++++++ .../_tinysnapshot/df_pairs_labs_frames.svg | 3486 +++++++++++++++++ .../{test-data.frame.R => test-dataframe.R} | 10 +- 6 files changed, 12463 insertions(+), 5 deletions(-) create mode 100644 inst/tinytest/_tinysnapshot/df_2var.svg create mode 100644 inst/tinytest/_tinysnapshot/df_pairs.svg create mode 100644 inst/tinytest/_tinysnapshot/df_pairs_by.svg create mode 100644 inst/tinytest/_tinysnapshot/df_pairs_by_vector.svg create mode 100644 inst/tinytest/_tinysnapshot/df_pairs_labs_frames.svg rename inst/tinytest/{test-data.frame.R => test-dataframe.R} (80%) diff --git a/inst/tinytest/_tinysnapshot/df_2var.svg b/inst/tinytest/_tinysnapshot/df_2var.svg new file mode 100644 index 00000000..8eecd7d4 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/df_2var.svg @@ -0,0 +1,114 @@ + + + + + + + + + + + + + +speed +dist +5 +10 +15 +20 +25 +0 +20 +40 +60 +80 +100 +120 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/inst/tinytest/_tinysnapshot/df_pairs.svg b/inst/tinytest/_tinysnapshot/df_pairs.svg new file mode 100644 index 00000000..6e689cde --- /dev/null +++ b/inst/tinytest/_tinysnapshot/df_pairs.svg @@ -0,0 +1,3069 @@ + + + + + + + + + + + + + + + + + + + + +Sepal.Length + + +4 +5 +6 +7 +8 +0 +5 +10 +15 +20 +25 +30 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.0 +3.0 +4.0 +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 +3 +5 +7 +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.5 +1.5 +2.5 +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +setosa +virginica +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +4.5 +5.5 +6.5 +7.5 +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Sepal.Width + + +2.0 +3.0 +4.0 +0 +5 +10 +15 +20 +25 +30 +35 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 +3 +5 +7 +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.5 +1.5 +2.5 +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +setosa +virginica +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +4.5 +5.5 +6.5 +7.5 +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.0 +3.0 +4.0 +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Petal.Length + + +1 +3 +5 +7 +0 +10 +20 +30 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.5 +1.5 +2.5 +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +setosa +virginica +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +4.5 +5.5 +6.5 +7.5 +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.0 +3.0 +4.0 +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 +3 +5 +7 +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Petal.Width + + +0.0 +1.0 +2.0 +0 +5 +10 +15 +20 +25 +30 +35 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +setosa +virginica +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +4 +6 +8 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2 +3 +4 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 +4 +6 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +1 +2 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + +Species + + +setosa +virginica +0 +10 +20 +30 +40 +50 + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/inst/tinytest/_tinysnapshot/df_pairs_by.svg b/inst/tinytest/_tinysnapshot/df_pairs_by.svg new file mode 100644 index 00000000..f085e2be --- /dev/null +++ b/inst/tinytest/_tinysnapshot/df_pairs_by.svg @@ -0,0 +1,3236 @@ + + + + + + + + + + + + + + + + + + + + +Sepal.Length + + +4 +5 +6 +7 +8 +0 +5 +10 +15 +20 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.0 +3.0 +4.0 +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 +3 +5 +7 +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.5 +1.5 +2.5 +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +setosa +virginica +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +4.5 +5.5 +6.5 +7.5 +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Sepal.Width + + +2.0 +3.0 +4.0 +0 +5 +10 +15 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 +3 +5 +7 +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.5 +1.5 +2.5 +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +setosa +virginica +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +4.5 +5.5 +6.5 +7.5 +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.0 +3.0 +4.0 +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Petal.Length + + +1 +3 +5 +7 +0 +10 +20 +30 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.5 +1.5 +2.5 +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +setosa +virginica +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +4.5 +5.5 +6.5 +7.5 +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.0 +3.0 +4.0 +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 +3 +5 +7 +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Petal.Width + + +0.0 +1.0 +2.0 +0 +5 +10 +15 +20 +25 +30 +35 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +setosa +virginica +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +4 +6 +8 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + + +4 +6 +8 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + +4 +6 +8 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2 +3 +4 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + + + + + + +2 +3 +4 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + +2 +3 +4 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 +4 +6 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + + + + + + +1 +4 +6 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + +1 +4 +6 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +1 +2 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + + + + + + + +0 +1 +2 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + + +0 +1 +2 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + +Species + + +setosa +virginica +0 +10 +20 +30 +40 +50 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/inst/tinytest/_tinysnapshot/df_pairs_by_vector.svg b/inst/tinytest/_tinysnapshot/df_pairs_by_vector.svg new file mode 100644 index 00000000..5496d9a1 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/df_pairs_by_vector.svg @@ -0,0 +1,2553 @@ + + + + + + + + + + + + + + + + + + + + +Sepal.Length + + +4 +5 +6 +7 +8 +0 +5 +10 +15 +20 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.0 +2.5 +3.0 +3.5 +4.0 +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 +2 +3 +4 +5 +6 +7 +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.5 +1.0 +1.5 +2.0 +2.5 +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +4.5 +5.5 +6.5 +7.5 +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Sepal.Width + + +2.0 +2.5 +3.0 +3.5 +4.0 +0 +5 +10 +15 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 +2 +3 +4 +5 +6 +7 +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.5 +1.0 +1.5 +2.0 +2.5 +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +4.5 +5.5 +6.5 +7.5 +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.0 +2.5 +3.0 +3.5 +4.0 +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Petal.Length + + +1 +2 +3 +4 +5 +6 +7 +0 +10 +20 +30 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.5 +1.0 +1.5 +2.0 +2.5 +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +4.5 +5.5 +6.5 +7.5 +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.0 +2.5 +3.0 +3.5 +4.0 +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 +2 +3 +4 +5 +6 +7 +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Petal.Width + + +0.0 +1.0 +2.0 +0 +5 +10 +15 +20 +25 +30 +35 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/inst/tinytest/_tinysnapshot/df_pairs_labs_frames.svg b/inst/tinytest/_tinysnapshot/df_pairs_labs_frames.svg new file mode 100644 index 00000000..49b7a7d2 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/df_pairs_labs_frames.svg @@ -0,0 +1,3486 @@ + + + + + + + + + + + + + + + + + + + + +Sepal.Length +Sepal.Length +Frequency + + +4 +5 +6 +7 +8 +0 +5 +10 +15 +20 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Sepal.Width +Sepal.Length + + +2.0 +3.0 +4.0 +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Petal.Length +Sepal.Length + + +1 +3 +5 +7 +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Petal.Width +Sepal.Length + + +0.5 +1.5 +2.5 +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Species +Sepal.Length + + +setosa +virginica +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Sepal.Length +Sepal.Width + + +4.5 +6.0 +7.5 +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Sepal.Width +Sepal.Width +Frequency + + +2.0 +3.0 +4.0 +0 +5 +10 +15 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Petal.Length +Sepal.Width + + +1 +3 +5 +7 +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Petal.Width +Sepal.Width + + +0.5 +1.5 +2.5 +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Species +Sepal.Width + + +setosa +virginica +2.0 +2.5 +3.0 +3.5 +4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Sepal.Length +Petal.Length + + +4.5 +6.0 +7.5 +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Sepal.Width +Petal.Length + + +2.0 +3.0 +4.0 +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Petal.Length +Petal.Length +Frequency + + +1 +3 +5 +7 +0 +10 +20 +30 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Petal.Width +Petal.Length + + +0.5 +1.5 +2.5 +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Species +Petal.Length + + +setosa +virginica +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Sepal.Length +Petal.Width + + +4.5 +6.0 +7.5 +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Sepal.Width +Petal.Width + + +2.0 +3.0 +4.0 +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Petal.Length +Petal.Width + + +1 +3 +5 +7 +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Petal.Width +Petal.Width +Frequency + + +0.0 +1.0 +2.0 +0 +5 +10 +15 +20 +25 +30 +35 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Species +Petal.Width + + +setosa +virginica +0.5 +1.0 +1.5 +2.0 +2.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Sepal.Length +Species + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +4 +6 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + +4 +6 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + +4 +6 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + +Sepal.Width +Species + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2 +3 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + +2 +3 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + +2 +3 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + +Petal.Length +Species + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 +5 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + +1 +5 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + +1 +5 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + +Petal.Width +Species + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +1.8 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + + +0 +1.8 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + + + +0 +1.8 +virginica +versicolor +setosa +0.0 +0.2 +0.4 +0.6 +0.8 +1.0 + + + + + + + + + + + + + + + +Species +Species +Count + + +setosa +virginica +0 +10 +20 +30 +40 +50 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/inst/tinytest/test-data.frame.R b/inst/tinytest/test-dataframe.R similarity index 80% rename from inst/tinytest/test-data.frame.R rename to inst/tinytest/test-dataframe.R index b6db99d7..8e6a32f2 100644 --- a/inst/tinytest/test-data.frame.R +++ b/inst/tinytest/test-dataframe.R @@ -2,23 +2,23 @@ source("helpers.R") using("tinysnapshot") # 2-variable data frame -> y ~ x -f = function() tinyplot(cars) +f = function() tinyplot(cars, theme = "clean2") expect_snapshot_plot(f, label = "df_2var") # 3+ variables -> pairs-style grid -f = function() tinyplot(iris) +f = function() tinyplot(iris, theme = "clean2") expect_snapshot_plot(f, label = "df_pairs") # pairs grid with a `by` grouping variable (column name) -f = function() tinyplot(iris, by = "Species") +f = function() tinyplot(iris, by = "Species", theme = "clean2") expect_snapshot_plot(f, label = "df_pairs_by") # `by` as a standalone vector (grouping var excluded from the grid) -f = function() tinyplot(iris[, 1:4], by = iris$Species) +f = function() tinyplot(iris[, 1:4], by = iris$Species, theme = "clean2") expect_snapshot_plot(f, label = "df_pairs_by_vector") # axis labels and per-panel frames toggled on -f = function() tinyplot(iris, by = "Species", labs = TRUE, frames = TRUE) +f = function() tinyplot(iris, by = "Species", labs = TRUE, frames = TRUE, theme = "clean2") expect_snapshot_plot(f, label = "df_pairs_labs_frames")