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

Reset graphics parameters after completion of diag_plots #17

Closed
bstaton1 opened this issue Aug 20, 2020 · 0 comments · Fixed by #22
Closed

Reset graphics parameters after completion of diag_plots #17

bstaton1 opened this issue Aug 20, 2020 · 0 comments · Fixed by #22
Labels
enhancement New feature or request

Comments

@bstaton1
Copy link
Owner

I figured out how to do this a while ago, but never implemented it. Here's an example:

# create a function that:
# 1.) stores the current par settings
# 2.) specifies new par settings
# 3.) makes some plots using these settings
# 4.) resets the par settings to the original ones on exit

test = function() {
  # obtain parameters of current device
  opar = par()
  
  # remove parameters that cannot be set
  opar = opar[-which(names(opar) %in% c("cin", "cra", "csi", "cxy", "din", "page"))]
  
  # set new parameters, for use within this function only
  par(mar = c(0,0,0,0), mfrow = c(2,2))
  plot(1:10)
  plot(1:10)
  plot(1:10)
  
  # when the function is done, reset the par to the original par settings
  on.exit(par(opar))
}

# test this out
plot(1:10, col = "blue")
test()
plot(1:10, col = "blue")
@bstaton1 bstaton1 added the enhancement New feature or request label Aug 20, 2020
bstaton1 added a commit that referenced this issue Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant