From 060b12b77d9f9f280c3e0c9418b6351eef77c9cb Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Fri, 19 Jul 2024 20:48:20 -0700 Subject: [PATCH 1/4] type = "j(itter)" --- R/tinyplot.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/R/tinyplot.R b/R/tinyplot.R index 0ea35dbf..280c0f9c 100644 --- a/R/tinyplot.R +++ b/R/tinyplot.R @@ -785,6 +785,12 @@ tinyplot.default = function( rm(xord) } } + + if (type %in% c("j", "jitter")) { + x = jitter(x) + y = jitter(y) + type = "p" + } xy = xy.coords(x = x, y = y) if (is.null(xlim)) xlim = range(xy$x[is.finite(xy$x)]) From 5ac91b4abb38353d637737d352d8f59c640d7122 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Fri, 19 Jul 2024 22:01:27 -0700 Subject: [PATCH 2/4] docs --- R/tinyplot.R | 1 + man/tinyplot.Rd | 1 + 2 files changed, 2 insertions(+) diff --git a/R/tinyplot.R b/R/tinyplot.R index a0344c20..f5ceea1a 100644 --- a/R/tinyplot.R +++ b/R/tinyplot.R @@ -76,6 +76,7 @@ #' over the extent of the data, but with no internal elements (see also the #' `empty` argument below). #' - Additional tinyplot types: +#' - `"jitter"` (alias `"j"`) for jittered points. #' - `"rect"`, `"segments"`, `"polygon"`, or `"polypath"`, which are all #' equivalent to their base counterparts, but don't require an existing #' plot window. diff --git a/man/tinyplot.Rd b/man/tinyplot.Rd index 1fb6ed72..5310ccd4 100644 --- a/man/tinyplot.Rd +++ b/man/tinyplot.Rd @@ -192,6 +192,7 @@ over the extent of the data, but with no internal elements (see also the \code{empty} argument below). \item Additional tinyplot types: \itemize{ +\item \code{"jitter"} (alias \code{"j"}) for jittered points. \item \code{"rect"}, \code{"segments"}, \code{"polygon"}, or \code{"polypath"}, which are all equivalent to their base counterparts, but don't require an existing plot window. From b5deaab609960d507427d404fedc5a80f07a4493 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Fri, 19 Jul 2024 22:02:31 -0700 Subject: [PATCH 3/4] add test --- inst/tinytest/_tinysnapshot/type_j.svg | 228 +++++++++++++++++++++++++ inst/tinytest/test-misc.R | 8 + 2 files changed, 236 insertions(+) create mode 100644 inst/tinytest/_tinysnapshot/type_j.svg diff --git a/inst/tinytest/_tinysnapshot/type_j.svg b/inst/tinytest/_tinysnapshot/type_j.svg new file mode 100644 index 00000000..c94cfb6e --- /dev/null +++ b/inst/tinytest/_tinysnapshot/type_j.svg @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + +ordered(Month) +5 +6 +7 +8 +9 + + + + + + + +Month +Temp + + + + + + + + +5 +6 +7 +8 +9 + + + + + +60 +70 +80 +90 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/inst/tinytest/test-misc.R b/inst/tinytest/test-misc.R index a94d325f..3324d15b 100644 --- a/inst/tinytest/test-misc.R +++ b/inst/tinytest/test-misc.R @@ -16,6 +16,14 @@ f = function () { expect_snapshot_plot(f, label = "type_l_empty") +# jittered points +f = function() { + set.seed(42) + tinyplot(Temp ~ Month | ordered(Month), airquality, type = "j", pch = 16) +} +expect_snapshot_plot(f, label = "type_j") + + # log axes f = function() { op = tpar(mfrow = c(1, 2)) From 767f6f9a91543b756da56b5dc058d44ec08723a0 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Fri, 19 Jul 2024 22:03:58 -0700 Subject: [PATCH 4/4] news --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index f5b76a68..6f6784d3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,6 +20,7 @@ New features: - `type = "rect"`. (#161 @grantmcdermott) - `type = "segments"`. (#163 @grantmcdermott) - `type = "histogram"` (alias `type = "hist"`). (#164 @grantmcdermott) + - `type = "jitter"` (alias `type = "j"`). (#170 @grantmcdermott) Misc: