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
11 changes: 8 additions & 3 deletions R/tinyplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,14 @@ tinyplot.default = function(
xaxs = NULL,
yaxs = NULL,
...) {
# save for plt_add()
options(tinyplot_last_call = match.call(tinyplot,
call = sys.call(sys.parent()), expand.dots = TRUE))
# save for tinyplot_add()
if (!isTRUE(add)) {
calls = sys.calls()
idx = grep("^tinyplot", sapply(calls, function(k) k[[1]]))
if (length(idx) > 0) {
options(tinyplot_last_call = calls[[idx[1]]])
}
}

## TODO: remove the global option above and move to this when density is refactored
# cal = match.call(call = sys.call(sys.parent()), expand.dots = TRUE)
Expand Down
64 changes: 64 additions & 0 deletions inst/tinytest/_tinysnapshot/tinyplot_add_multiple.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 20 additions & 3 deletions inst/tinytest/test-tinyplot_add.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,26 @@ using("tinysnapshot")

f = function() {
tinyplot(Sepal.Width ~ Sepal.Length | Species,
facet = ~Species,
data = iris,
type = "p")
facet = ~Species,
data = iris,
type = "p")
tinyplot_add(type = type_lm())
}
expect_snapshot_plot(f, label = "tinyplot_add")


f = function() {
k = seq(-3, 3, length.out = 100)
tinyplot(x = k, type = type_function(dnorm))
tinyplot_add(
x = k[k < -1.96],
ymax = dnorm(k[k < -1.96]),
ymin = 0,
type = "ribbon")
tinyplot_add(
x = k[k > 1],
ymax = dnorm(k[k > 1]),
ymin = 0,
type = "ribbon")
}
expect_snapshot_plot(f, label = "tinyplot_add_multiple")