diff --git a/NEWS.md b/NEWS.md index 077f682c..2b17aaa9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,14 @@ where the formatting is also better._ ## 0.1.0.99 (dev version) +New features: + +- Support for `type = "n"` (empty) plots. (#157 @grantmcdermott) + +Misc: + +- Various documentation improvements. + ## 0.1.0 Our first CRAN submission! This v0.1.0 release includes the following new diff --git a/R/draw_legend.R b/R/draw_legend.R index b4bdc02c..0daafd96 100644 --- a/R/draw_legend.R +++ b/R/draw_legend.R @@ -175,6 +175,9 @@ draw_legend = function( if (is.null(legend_args[["y.intersp"]])) legend_args[["y.intersp"]] = 1.25 if (is.null(legend_args[["seg.len"]])) legend_args[["seg.len"]] = 1.25 } + if (type == "n" && isFALSE(gradient)) { + if (is.null(legend_args[["pch"]])) legend_args[["pch"]] = par("pch") + } if (is.null(legend_args[["legend"]])) { diff --git a/R/tinyplot.R b/R/tinyplot.R index 292c8dd7..d5908ac3 100644 --- a/R/tinyplot.R +++ b/R/tinyplot.R @@ -70,9 +70,9 @@ #' @param type character string giving the type of plot desired. Options are: #' - The same set of 1-character values supported by plot: "p" for points, "l" #' for lines, "b" for both points and lines, "c" for empty points joined by -#' lines, "o" for overplotted points and lines, "s" and "S" for stair steps -#' and "h" for histogram-like vertical lines. "n" does not produce -#' any points or lines. +#' lines, "o" for overplotted points and lines, "s" and "S" for stair steps, +#' and "h" for histogram-like vertical lines. Specifying "n" produces an empty +#' plot over the extent of the data, but with no internal elements. #' - Additional tinyplot types: "density" for densities, "polygon" for #' polygons, "pointrange" or "errorbar" for segment intervals, and "polygon", #' "ribbon" or "area" for polygon intervals (where area plots are a special @@ -1372,6 +1372,8 @@ tinyplot.default = function( lty = ilty, lwd = ilwd ) + } else if (type == "n") { + # Blank plot } else { stop("`type` argument not supported.", call. = FALSE) } diff --git a/inst/tinytest/_tinysnapshot/type_n.svg b/inst/tinytest/_tinysnapshot/type_n.svg new file mode 100644 index 00000000..b81d12af --- /dev/null +++ b/inst/tinytest/_tinysnapshot/type_n.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + +Petal.Length +Sepal.Length + + + + + + + + +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + diff --git a/inst/tinytest/_tinysnapshot/type_n_by.svg b/inst/tinytest/_tinysnapshot/type_n_by.svg new file mode 100644 index 00000000..429d5b3d --- /dev/null +++ b/inst/tinytest/_tinysnapshot/type_n_by.svg @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + +Species +setosa +versicolor +virginica + + + + + + + +Petal.Length +Sepal.Length + + + + + + + + + + +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + +4.5 +5.0 +5.5 +6.0 +6.5 +7.0 +7.5 +8.0 + + + diff --git a/inst/tinytest/test-misc.R b/inst/tinytest/test-misc.R index 98eee179..09f15606 100644 --- a/inst/tinytest/test-misc.R +++ b/inst/tinytest/test-misc.R @@ -1,6 +1,18 @@ source("helpers.R") using("tinysnapshot") +# empty plot(s) +f = function () { + tinyplot(Sepal.Length ~ Petal.Length, data = iris, type = "n") +} +expect_snapshot_plot(f, label = "type_n") +# empty plot(s) +f = function () { + tinyplot(Sepal.Length ~ Petal.Length | Species, data = iris, type = "n") +} +expect_snapshot_plot(f, label = "type_n_by") + +# log axes f = function() { op = tpar(mfrow = c(1, 2)) plot(Temp ~ Day, data = airquality, log = "x") @@ -33,9 +45,6 @@ f = function() { } expect_snapshot_plot(f, label = "arg_log_yx") -## https://bugs.r-project.org/show_bug.cgi?id=18337 -# exit_if_not(getRversion() >= "4.4.0") - f = function() { op = tpar(mfrow = c(1, 1)) m = transform(mtcars, cyl = factor(cyl)) diff --git a/man/tinyplot.Rd b/man/tinyplot.Rd index 11e47a91..7dfe30bd 100644 --- a/man/tinyplot.Rd +++ b/man/tinyplot.Rd @@ -182,9 +182,9 @@ should be taken. A matrix is converted to a data frame.} \itemize{ \item The same set of 1-character values supported by plot: "p" for points, "l" for lines, "b" for both points and lines, "c" for empty points joined by -lines, "o" for overplotted points and lines, "s" and "S" for stair steps -and "h" for histogram-like vertical lines. "n" does not produce -any points or lines. +lines, "o" for overplotted points and lines, "s" and "S" for stair steps, +and "h" for histogram-like vertical lines. Specifying "n" produces an empty +plot over the extent of the data, but with no internal elements. \item Additional tinyplot types: "density" for densities, "polygon" for polygons, "pointrange" or "errorbar" for segment intervals, and "polygon", "ribbon" or "area" for polygon intervals (where area plots are a special