Q. How do I use a static scale or a fixed range for an axis?
A.
par(xlim = ..., ylim = ...)
to set a fixed range
for the x-axis and y-axis.par(xlim = NULL, ylim = NULL)
to clear the
setting.Q. How to style the frame in which the plot is made?
A. The syntax to use is:
<- animate$new(width, height, attr = list(style = MY_STYLE)) device
where MY_STYLE can be:
MY_STYLE <- "border:1px solid black;"
MY_STYLE <- "border:1px solid lightgray; border-radius:5px;"
Q. I heard there is a trick for developing animated plot in a code chunk of an R Markdown Document?
A. Yes, the function below is a handy trick to set up the device and render the output in a code chunk.
<- function(..., width = 600, height = 600, options = click_to_play()) {
animate_it # Setup
require(animate) # 'require' is designed for use inside functions
<- animate$new(width, height, virtual = TRUE,
device attr = list(style = "border:1px solid lightgray"))
attach(device) # Make methods of the device available in the namespace
::f(...)() # Main code
pryrrmd_animate(device, options = options) # Embed animated plot in R Markdown Document
}
# Usage
animate_it({
<- new_id(1:10)
id plot(1:10, runif(10, 0, 1), id = id)
plot(1:10, runif(10, 0, 1), id = id, transition = TRUE)
})
Q. Are there any tips to improve the workflow developing in the R console?
A. Yes, I sometimes use the following for development in the R console.
<- function(width = 600, height = 600) {
setup require(animate)
<- animate$new(width, height, attr = list(style = "border:1px solid lightgray"))
device attach(device)
}
<- function() {
cleanup clear()
off()
detach(device)
}
# Usage
setup()
<- new_id(1:10)
id plot(1:10, runif(10, 0, 1), id = id)
plot(1:10, runif(10, 0, 1), id = id, transition = TRUE)
cleanup()
Q. What does set_max_stacksize
do? Why
does the device need memory?
A. set_max_stacksize
sets the cap of
the internal memory of the device. Memory is needed when one wants to
make an animated plot and then export it to a file. This is by default
switched on, since the memory usage is generally low, and it makes more
sense to have a plot ready to be exported when it is complete.