Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tinyplot_add call multiple times #256

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

vincentarelbundock
Copy link
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
3 checks passed
@grantmcdermott
Copy link
Owner

Ah, good catch thanks!

@grantmcdermott
Copy link
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))

🎉🎉

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