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: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ where the formatting is also better._
[custom types](https://grantmcdermott.com/tinyplot/vignettes/types.html#custom-types)
in the `Types` vignette. (#531 @grantmcdermott)

### Bugs

- Fixed Issue #545 where xaxs/yaxs were not restored when set by an internal function.
(#545 @zeileis)

### Breaking changes

## v0.6.0
Expand Down
15 changes: 12 additions & 3 deletions R/facet.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,18 @@ draw_facet_window = function(
## dynamic margins flag
dynmar = isTRUE(get_tpar("dynmar", tpar_list = tpars))

## optionally allow to modify the style of axis interval calculation
if (!is.null(xaxs)) par(xaxs = xaxs)
if (!is.null(yaxs)) par(yaxs = yaxs)
## optionally allow to modify and restore the style of axis interval calculation
if (!is.null(xaxs) || !is.null(yaxs)) {
op = par()
if (!is.null(xaxs)) {
par(xaxs = xaxs)
on.exit(par(xaxs = op$xaxs), add = TRUE)
}
if (!is.null(yaxs)) {
par(yaxs = yaxs)
on.exit(par(yaxs = op$yaxs), add = TRUE)
}
}

if (nfacets > 1) {
# Set facet margins (i.e., gaps between facets)
Expand Down
125 changes: 125 additions & 0 deletions inst/tinytest/_tinysnapshot/issue_545_xaxs_yaxs_restoration.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 33 additions & 18 deletions inst/tinytest/test-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ source("helpers.R")
using("tinysnapshot")

# empty plot(s)
f = function () {
f = function() {
tinyplot(Sepal.Length ~ Petal.Length, data = iris, type = "n")
}
expect_snapshot_plot(f, label = "type_n")
f = function () {
f = function() {
tinyplot(Sepal.Length ~ Petal.Length | Species, data = iris, type = "n")
}
expect_snapshot_plot(f, label = "type_n_by")
f = function () {
f = function() {
tinyplot(Sepal.Length ~ Petal.Length | Species, data = iris, type = "l", empty = TRUE)
}
expect_snapshot_plot(f, label = "type_l_empty")
Expand All @@ -35,31 +35,31 @@ f = function() {
plot(Temp ~ Day, data = airquality, log = "x")
tinyplot(Temp ~ Day, data = airquality, log = "x")
tpar(op)
}
}
expect_snapshot_plot(f, label = "arg_log_x")

f = function() {
op = tpar(mfrow = c(1, 2))
plot(Temp ~ Day, data = airquality, log = "y")
tinyplot(Temp ~ Day, data = airquality, log = "y")
tpar(op)
}
}
expect_snapshot_plot(f, label = "arg_log_y")

f = function() {
op = tpar(mfrow = c(1, 2))
plot(Temp ~ Day, data = airquality, log = "xy")
tinyplot(Temp ~ Day, data = airquality, log = "xy")
tpar(op)
}
}
expect_snapshot_plot(f, label = "arg_log_xy")

f = function() {
op = tpar(mfrow = c(1, 2))
plot(Temp ~ Day, data = airquality, log = "yx")
tinyplot(Temp ~ Day, data = airquality, log = "yx")
tpar(op)
}
}
expect_snapshot_plot(f, label = "arg_log_yx")

f = function() {
Expand All @@ -80,19 +80,25 @@ f = function() {
expect_snapshot_plot(f, label = "addTRUE")

# formatting axis tick labels
f = function() plt(
I(decrease/100) ~ treatment, data = OrchardSprays,
xaxl = tolower, yaxl = "percent"
)
f = function() {
plt(
I(decrease / 100) ~ treatment,
data = OrchardSprays,
xaxl = tolower, yaxl = "percent"
)
}
expect_snapshot_plot(f, label = "xaxl_yaxl")

# formatting axis breaks and tick labels at the same time
f = function() plt(
I(decrease/100) ~ treatment, data = OrchardSprays,
xaxb = c("A", "C", "E", "G"), xaxl = tolower,
yaxb = c(0, 0.2, 0.5, 1, 1.4), yaxl = "percent",
grid = TRUE
)
f = function() {
plt(
I(decrease / 100) ~ treatment,
data = OrchardSprays,
xaxb = c("A", "C", "E", "G"), xaxl = tolower,
yaxb = c(0, 0.2, 0.5, 1, 1.4), yaxl = "percent",
grid = TRUE
)
}
expect_snapshot_plot(f, label = "xaxb_yaxb_xaxl_yaxl")


Expand All @@ -101,7 +107,8 @@ if (requireNamespace("png", quietly = TRUE)) {
f = function() {
tmp_path = tempfile(fileext = ".png")
suppressWarnings(tinyplot(
Sepal.Length ~ Petal.Length, data = iris,
Sepal.Length ~ Petal.Length,
data = iris,
file = tmp_path, width = 4, height = 4
))
obj = png::readPNG(tmp_path, info = TRUE)
Expand All @@ -114,3 +121,11 @@ if (requireNamespace("png", quietly = TRUE)) {
expect_equal(f(), c(1200, 1200), label = "png_size")
}


# Issue #545: Restore xaxs and yaxs par settings when modified internally
f = function() {
par(mfrow = c(1, 2))
tinyplot(~species, data = penguins, type = type_barplot())
tinyplot(1:10, pch = 19, cex = 2, main = "dots not cut off")
}
expect_snapshot_plot(f, label = "issue_545_xaxs_yaxs_restoration")