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
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ where the formatting is also better._
New features:

- Support for additional plot types:
- `type = "n"`, i.e. empty plot. (#157 @grantmcdermott)
- `type = "n"`, i.e. empty plot. Since `type = "n"` implicitly assumes points,
which limits the type of legend that can be drawn alongside the empty plot, we
have also added a companion `empty` argument that can be used alongside any
plot type. (#157, #167 @grantmcdermott)
- `type = "boxplot"`. Simultaneously enables `plt(numeric ~ factor)`
support, first raised in #2, so that a boxplot is automatically plotted if a
numeric is plotted against a factor. (#154 @grantmcdermott)
Expand Down
15 changes: 12 additions & 3 deletions R/tinyplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,20 @@
#' 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. Specifying "n" produces an empty
#' plot over the extent of the data, but with no internal elements.
#' plot over the extent of the data, but with no internal elements (see also
#' the `empty` argument below).
#' - Additional tinyplot types: "boxplot" for boxplots, "density" for
#' densities, "polygon" or "polypath" for polygons, "pointrange" or"errorbar"
#' for segment intervals, and "ribbon" or "area" for polygon intervals (where
#' area plots are a special case of ribbon plots with `ymin` set to 0 and
#' `ymax` set to `y`; see below).
#' @param empty logical indicating whether the interior plot region should be
#' left empty. The default is `FALSE`. Setting to `TRUE` has a similar effect
#' to invoking `type = "n"` above, except that any legend artifacts owing to a
#' particular plot type (e.g., lines for `type = "l"` or squares for
#' `type = "area"`) will still be drawn correctly alongside the empty plot. In
#' contrast,`type = "n"` implicitly assumes a scatterplot and so any legend
#' will only depict points.
#' @param xmin,xmax,ymin,ymax minimum and maximum coordinates of relevant area
#' or interval plot types. Only used when the `type` argument is one of
#' "rect" or "segments" (where all four min-max coordinates are required), or
Expand Down Expand Up @@ -250,7 +258,7 @@
#' graphics windows.
#' @param height numeric giving the plot height in inches. Same considerations as
#' `width` (above) apply, e.g. will default to `tpar("file.height")` if not
#' specified.
#' specified.
#' @param ... other graphical parameters. See \code{\link[graphics]{par}} or
#' the "Details" section of \code{\link[graphics]{plot}}.
#'
Expand Down Expand Up @@ -489,6 +497,7 @@ tinyplot.default = function(
file = NULL,
width = NULL,
height = NULL,
empty = FALSE,
...) {

dots = list(...)
Expand Down Expand Up @@ -1372,7 +1381,7 @@ tinyplot.default = function(

# empty plot flag
empty_plot = FALSE
if (type=="n" || ((length(xx)==0) && !(type %in% c("rect","segments")))) {
if (isTRUE(empty) || type=="n" || ((length(xx)==0) && !(type %in% c("rect","segments")))) {
empty_plot = TRUE
}

Expand Down
76 changes: 76 additions & 0 deletions inst/tinytest/_tinysnapshot/type_l_empty.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion inst/tinytest/test-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ 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")
f = function () {
tinyplot(Sepal.Length ~ Petal.Length | Species, data = iris, type = "l", empty = TRUE)
}
expect_snapshot_plot(f, label = "type_l_empty")


# log axes
f = function() {
Expand Down
12 changes: 11 additions & 1 deletion man/tinyplot.Rd

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