Skip to content

tinyplot_add call multiple times#256

Merged
grantmcdermott merged 1 commit intograntmcdermott:mainfrom
vincentarelbundock:add_save
Nov 14, 2024
Merged

tinyplot_add call multiple times#256
grantmcdermott merged 1 commit intograntmcdermott:mainfrom
vincentarelbundock:add_save

Conversation

@vincentarelbundock
Copy link
Copy Markdown
Collaborator

My previous PR did not allow users to call tinyplot_add() multiple times. This can be very useful in some cases (example below).

Also, the previous PR sometimes failed when tinyplot() was called inside another function. Now, we run sys.calls() and grep through the list of active calls to find the most recent ^tinyplot, and we save that one.

library(tinyplot)
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")

@grantmcdermott grantmcdermott merged commit 3ed86b8 into grantmcdermott:main Nov 14, 2024
@grantmcdermott
Copy link
Copy Markdown
Owner

Ah, good catch thanks!

@grantmcdermott
Copy link
Copy Markdown
Owner

Just made use of this for adding multiple confidence interval bands over some data a la:

library(tinyplot)

plt(
  Temp ~ Day | Month, airquality,
  facet = "by", facet.args = list(bg = "grey90"),
  legend = FALSE, grid = TRUE, axes = "l",
  palette = "dark2", ylim = c(50, 100)
)
plt_add(type = "lm")
plt_add(type = type_lm(level = 0.8))

🎉🎉

@vincentarelbundock vincentarelbundock deleted the add_save branch September 9, 2025 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants