In the example below I would like to be able to control when I go to the next plot by a using mouse click (or keyboard entry)
for (i in 1:5){
plot(1:i)
Sys.sleep(1)
#add something here that requests mouse click to proceed
}
Is this possible? There is a setting in the X11() help file caled ‘clickToConfirm’ but I can’t work out what that does.
It would also be helpful to me to be to be able to scroll back and forth through plots using the arrow keys. Is this possible?
Currently if I need to look at lots of plots I output them into a big .pdf file and scroll though them all there, but that is a bit cumbersome.
Thanks
Tom
In R, that would be done by setting
par(ask=TRUE). Try the following code, which shows how to reset the par when exiting the function :If you want to keep a history to browse through, you can either open a window and click on
recordingin theHistorymenu, or you can open the window yourself with the history on. Demonstrated in a function :This will however keep all previous plots in the history for browsing as well, so if you run this code 3 times you’ll have 15 plots in the plot history. Also note that the open plot window will keep on recording until you turn off the recording in the menu.
You can play with the plot history, as you’ll have a variable
.SavedPlotswhich contains the saved plot history. It can be cleared using the menuHistory > clear historyin the plot window. If you want to clear the history from the console, you could hack that byBut I advise you not to do this, as changing the
.SavedPlotsvariable can cause R to crash.See also
?windowsand ?recordPlot for a bit more information. But as you’re getting close to the internal code of R, be warned that you can get pretty awkward behaviour if you start playing around with these things.