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
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 0.5.0
Date: 2025-09-21 18:31:22 UTC
SHA: a0d3b9a79ee0f33db7841eba7e3e583cde73ee8e
Version: 0.6.0
Date: 2025-11-26 21:36:13 UTC
SHA: 3080d0ab861e2cf1f6d463e4784a8d4f6653a6d4
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: tinyplot
Type: Package
Title: Lightweight Extension of the Base R Graphics System
Version: 0.5.0.99
Date: 2025-09-21
Version: 0.6.0
Date: 2025-11-26
Authors@R:
c(
person(
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ importFrom(grDevices,cairo_pdf)
importFrom(grDevices,col2rgb)
importFrom(grDevices,colorRampPalette)
importFrom(grDevices,convertColor)
importFrom(grDevices,dev.cur)
importFrom(grDevices,dev.list)
importFrom(grDevices,dev.new)
importFrom(grDevices,dev.off)
Expand Down
28 changes: 14 additions & 14 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ _If you are viewing this file on CRAN, please check the
[latest NEWS](https://grantmcdermott.com/tinyplot/NEWS.html) on our website
where the formatting is also better._

## Dev version
## v0.6.0

### Breaking changes

Expand Down Expand Up @@ -76,7 +76,7 @@ where the formatting is also better._
`tinyplot()` and that it thus has access to the local definition to all
variables such as `x` and `y` etc. (#507 @zeileis)

## 0.5.0
## v0.5.0

### New features

Expand Down Expand Up @@ -138,7 +138,7 @@ where the formatting is also better._
with the CI implementation.
- Add a `devcontainer.json` file for remote testing. (#480 @grantmcdermott)

## 0.4.2
## v0.4.2

### New features

Expand Down Expand Up @@ -169,7 +169,7 @@ where the formatting is also better._
can also call them in a base plot layer, relaxing the requirement that they
must be called as part of a subsequent plot layer via `tinyplot_add()`. (#422 @grantmcdermott)

## 0.4.1
## v0.4.1

### Bug fixes

Expand All @@ -180,7 +180,7 @@ where the formatting is also better._

- Revert minimum compatible R version to 4.0.0 (#416 @grantmcdermott)

## 0.4.0
## v0.4.0

### New features:

Expand Down Expand Up @@ -278,7 +278,7 @@ where the formatting is also better._
logic was mostly an artifact of development inertia and this new nesting logic
should simplify the creation of certain plot types. (#331 @grantmcdermott)

## 0.3.0
## v0.3.0

### New features

Expand Down Expand Up @@ -453,7 +453,7 @@ grouping variables (thanks to @strengjacke for reporting #213).
- The new functional type processing system also means that each type now
has its own help page (e.g. `?type_hist`, `type_ridge`, etc.)

## 0.2.1
## v0.2.1

New Features:

Expand Down Expand Up @@ -502,7 +502,7 @@ Internals:
- Revamped formula processing that allows for better sanity checking and
edge-case logic. (#197 @zeileis)

## 0.2.0
## v0.2.0

New features:

Expand Down Expand Up @@ -530,7 +530,7 @@ Misc:

- Various documentation improvements.

## 0.1.0
## v0.1.0

Our first CRAN submission! This v0.1.0 release includes the following new
features and updates:
Expand Down Expand Up @@ -626,7 +626,7 @@ approach). (#145 @vincentarelbundock & @grantmcdermott)
calculates `density` grid coords. (#150 @grantmcdermott)


## 0.0.5
## v0.0.5

**IMPORTANT BREAKING CHANGE:**

Expand Down Expand Up @@ -670,7 +670,7 @@ see the following GitHub comment, as well as the discussion that preceded it:
https://github.com/grantmcdermott/plot2/issues/22#issuecomment-1928472754


## 0.0.4
## v0.0.4

Website:

Expand Down Expand Up @@ -727,7 +727,7 @@ outer gap to outside of the graphics device unchanged. (#94 @grantmcdermott)
- Fix bug where grid wasn't auto-expanding correctly for area plots. (#92
@grantmcdermott)

## 0.0.3
## v0.0.3

Breaking changes:

Expand Down Expand Up @@ -765,7 +765,7 @@ Bug fixes:
- Setting a global palette, e.g. `palette("ggplot2")` is now respected. (#44
@grantmcdermott)

## 0.0.2
## v0.0.2

Breaking changes:

Expand All @@ -792,6 +792,6 @@ Project:
- @vincentarelbundock and @zeileis have joined the project as core contributors.
🎉

## 0.0.1
## v0.0.1

* Initial release on GitHub.
19 changes: 17 additions & 2 deletions R/align_layer.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
# Ensure added layers respect the x-axis order of the original plot layer
# (e.g., when adding lines or ribbons on top of errorbars)
align_layer = function(settings) {
# Retrieve xlabs from current and original layers
# Retrieve xlabs and plot/device metadata from original layer
tinyplot_env = get(".tinyplot_env", envir = parent.env(environment()))
xlabs_orig = tryCatch(get("xlabs_orig", envir = tinyplot_env), error = function(e) NULL)
usr_orig = tryCatch(get("usr_orig", envir = tinyplot_env), error = function(e) NULL)
dev_orig = tryCatch(get("dev_orig", envir = tinyplot_env), error = function(e) NULL)

# Validate that we're adding to the same plot (not a stale xlabs from previous plot)
if (is.null(usr_orig) || is.null(dev_orig) || dev_orig != dev.cur()) {
return(invisible())
}
# Normalize current usr for comparison (accounting for flipped plots)
usr_layer = if (isTRUE(settings$flip)) par("usr")[c(3,4,1,2)] else par("usr")
if (!identical(usr_orig, usr_layer)) {
return(invisible())
}

# xlabs of current layer
xlabs_layer = settings[["xlabs"]]
xlabs_orig = get("xlabs", envir = get(".tinyplot_env", envir = parent.env(environment())))

# Only adjust if original layer has named xlabs
if (!is.null(names(xlabs_orig))) {
Expand Down
12 changes: 10 additions & 2 deletions R/tinyplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
#' out existing `plot` calls for `tinyplot` (or its shorthand alias `plt`),
#' without causing unexpected changes to the output.
#'
#' @importFrom grDevices axisTicks adjustcolor cairo_pdf colorRampPalette extendrange palette palette.colors palette.pals hcl.colors hcl.pals xy.coords png jpeg pdf svg dev.off dev.new dev.list
#' @importFrom grDevices axisTicks adjustcolor cairo_pdf colorRampPalette dev.cur dev.list dev.off dev.new extendrange hcl.colors hcl.pals jpeg palette palette.colors palette.pals pdf png svg xy.coords
#' @importFrom graphics abline arrows axis Axis axTicks box boxplot grconvertX grconvertY hist lines mtext par plot.default plot.new plot.window points polygon polypath segments rect text title
#' @importFrom utils modifyList head tail
#' @importFrom stats na.omit setNames
Expand Down Expand Up @@ -871,7 +871,7 @@ tinyplot.default = function(

# ensure axis aligment of any added layers
if (!add) {
assign("xlabs", settings[["xlabs"]], envir = get(".tinyplot_env", envir = parent.env(environment())))
assign("xlabs_orig", settings[["xlabs"]], envir = get(".tinyplot_env", envir = parent.env(environment())))
} else {
align_layer(settings)
}
Expand Down Expand Up @@ -1340,6 +1340,14 @@ tinyplot.default = function(
#

if (!add) {
# Capture device and usr before recordGraphics (in current plot context)
current_dev = dev.cur()
current_usr = if (isTRUE(settings$flip)) par("usr")[c(3,4,1,2)] else par("usr")

# Store usr and dev for validating layer alignment
assign("usr_orig", current_usr, envir = get(".tinyplot_env", envir = parent.env(environment())))
assign("dev_orig", current_dev, envir = get(".tinyplot_env", envir = parent.env(environment())))

recordGraphics(
{
apar = par(no.readonly = TRUE)
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ tinyplot(Sepal.Length ~ Petal.Length | Species, data = iris) # formu

If you would prefer to save on a few keystrokes, you can use the
shorthand `plt()` alias instead of typing out `tinyplot()` in full.
Here’s the same plot with this shorthand alias, plus a few aesthetic
tweaks:
Here’s the same plot with this shorthand `plt()` alias, as well as an
added `"lm"` layer and a few aesthetic tweaks:

``` r
plt(
Expand All @@ -103,6 +103,7 @@ plt(
palette = "dark", pch = 16,
grid = TRUE, frame = FALSE
)
plt_add(type = "lm")
```

<img src="man/figures/README-quickstart3-1.png" style="width:70.0%" />
Expand All @@ -114,6 +115,7 @@ built-in themes for convenient plot customization:
tinytheme("clean2")

plt(Sepal.Length ~ Petal.Length | Species, data = iris)
plt_add(type = "lm")
```

<img src="man/figures/README-quickstart_theme-1.png"
Expand Down
7 changes: 5 additions & 2 deletions README.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ tinyplot(Sepal.Length ~ Petal.Length | Species, data = iris) # formu
```

If you would prefer to save on a few keystrokes, you can use the shorthand
`plt()` alias instead of typing out `tinyplot()` in full. Here's the
same plot with this shorthand alias, plus a few aesthetic tweaks:
`plt()` alias instead of typing out `tinyplot()` in full. Here's the same plot
with this shorthand `plt()` alias, as well as an added `"lm"` layer and a few
aesthetic tweaks:

```{r quickstart3}
plt(
Expand All @@ -115,6 +116,7 @@ plt(
palette = "dark", pch = 16,
grid = TRUE, frame = FALSE
)
plt_add(type = "lm")
```

Speaking of aesthetic tweaks, **tinyplot** also provides a set of built-in
Expand All @@ -124,6 +126,7 @@ themes for convenient plot customization:
tinytheme("clean2")

plt(Sepal.Length ~ Petal.Length | Species, data = iris)
plt_add(type = "lm")
```

Themes are persistent and will be applied to subsequent plots. For example, here
Expand Down
6 changes: 5 additions & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## Overview

**tinyplot** v0.5.0 a minor release with some new features and bug fixes.
**tinyplot** v0.6.0 a minor release containing mostly bug fixes.

_Note:_ This is a re-submission that fixes a regression discovered by CRAN's
revdep checks (specific to the **parttree** package). Apologies for missing it
the first time around.

## Test environments
Arch Linux (local)
Expand Down
86 changes: 37 additions & 49 deletions inst/tinytest/_tinysnapshot/pointrange_with_layers_flipped.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions inst/tinytest/test-type_pointrange.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ fun = function() {
y ~ x, ymin = ymin, ymax = ymax,
data = coefs,
type = "pointrange",
theme = "basic",
theme = "classic",
flip = TRUE
)
tinyplot_add(type = "ribbon")
tinyplot_add(type = "hline", lty = 2)
tinyplot_add(type = "vline", lty = 2)
}
expect_snapshot_plot(fun, label = "pointrange_with_layers_flipped")
Binary file modified man/figures/README-quickstart2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-quickstart3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-quickstart4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-quickstart5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-quickstart_theme-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading