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: diff --git a/R/tinyplot.R b/R/tinyplot.R index 3aa6d1c6..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. @@ -790,6 +791,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)]) 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)) 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.