In matplotlib or matlab you can do something like:
figure(n)
clf()
How do we do this in R?
The desired action is to bring up a new blank plotting window in window "n" i.e. n=3. All subsequent plotting commands will appear in this active window.
I've definitely figured this out before but I always have to look it up when I come back to R.
I think "x11" plus some option might be the trick.
If you have multiple graphics devices open then dev.list will show a list of the open devices. The dev.cur function returns which of those is the current/active device. You can use dev.set to choose which of the open devices to make the current or active device (where new plots will go to). You could also use dev.next and dev.prev along with dev.set to cycle through the active devices. You can look at the names of the return values from these functions to see what kinds of devices they are, this may help to rotate through screen devices while skipping file devices.
If you are in a mulptiple figure setup (par(mfrow=c(3,2))) within a single device, then you can use par(mfg=c(r,c)) to set the figure in the r'th row and c'th column as the next figure to be plotted into.
Related
This is a workflow related question. I'm trying out working only (or mostly) in the Rmarkdown source window with the options set to "Chunk output inline". So with R open, there is just one big window -The environment, Console and File windows being minimized.
My question: Is there some option to change the number of columns displayed? I want to increase the numbers of columns visible without scrolling (see screenshot below), and since there is enough space I think it should be possible to display more of them.
Many thanks!
Solution: There is an option. Just add cols.print = 12 (or whatever number you want) to global options.
Also, people might find this 'manual' on markdown useful: https://bookdown.org/yihui/rmarkdown/html-document.html#paged-printing
When Octave draws a plot, I would like it to set that to be the active window automatically, so that it becomes visible and I don't have to click back and forth between windows to see if the code and plot have finished. Is this possible? Since it would require reaching outside of Octave and controlling the OS, I'm not sure; it depends on whether or not that capability is part of Octave but I haven't found a reference for it yet.
I can always tell Octave to close the figure before opening a new one in the code, but that could prevent me from drawing multiple plots on the same axes, and it would require me to code that command in every time. It would be nice if there were a direct way just to bring the plot to be visible and take dominance over other windows.
EDIT: Somehow, although I noted that Octave would be required to control the OS to achieve this, I completely forgot to mention what that was... I'm running Windows 10 with the default window manager; I believe that would be the Desktop Window Manager.
When you plot something on a figure (whether you specify the figure you're plotting to within the plot command explicitly or simply let it plot into the currently active figure implicitly), this does not automatically raise the figure window to the forefront.
To do so, call the figure again using the figure function, along with the handle that you want to raise.
Alternatively, if you're sure that the figure you want to raise is the currently active one, you can simply use the shg command (which is effectively equivalent to figure(gcf))
E.g.
Fig1 = figure; % (or figure(1) if you want to be explicit)
Fig2 = figure; % (or figure(2) if you want to be explicit)
figure(Fig1); plot(1:10); % raise Fig1 to the forefront, and plot.
PS: Note that there was a bug affecting this behaviour until recently (coincidentally submitted by yours truly :p See https://savannah.gnu.org/bugs/?45943 ). This is fixed in the latest version of octave though (i.e. 5.1.0)
If I have multiple pop-up figures in R initiated with window(). However, they are all plotted in the same spot, masking each other. Is there a way to automatically space them out on the screen(s). What I am looking for is an R implementation of this Matlab function: https://se.mathworks.com/matlabcentral/fileexchange/37176-distribute-figures.
I am aware of the par(mfrow) and the layout() options for multipanel figures but they are not what I am looking for.
The function name is windows, not window. (It is only available in MS Windows, not other platforms.) It has arguments xpos and ypos that set the position. If you want your windows in random positions, do something like this:
windows(xpos = -300*runif(1), ypos = 200*runif(1))
(The negative value for xpos measures from the right side of the screen.)
If the graphics windows already exist, you can use arrangeWindows() to distribute them on your screen. (Again, only in MS Windows.)
Is there an underlying reason within R's architecture that prevents the use of a function that updates a plotting device with a second high-level plotting function?
Matlab has some functions, like colorbar, that seem to work in this way - by shifting the original plot to make room for the new element: http://uk.mathworks.com/help/matlab/ref/colorbar.html
It seems to me that this would require splitting the screen (e.g. split.screen, layout) while moving the previous plot to one of the subareas.
For this to work, I guess that the calls to the previous device must be stored in order to update the new split screen - or is there another way?
I am making some graphs with R and I am coping them to Word. I was coping them as metafiles but Word doesn't seem to be able to cope with them. The other option in R to copy graphs is a bitmap, but when I use this the quality of the graphs in word is terrible.
I saw some answers about changing the resolution in this website but only if I saved the graphs which I would like to avoid. Is there a way of changing the resolution for copied graphs?
Thanks,
sbg
When the graphs are onscreen, they are drawn for a screen resolution (i.e. 72dpi). For print, you need to use at least 300dpi, or switch to a vector format. Word can import graphs in Windows Metafile (.wmf) format; but your other option is to save the plot using, e.g.,
png("my plot.png", res = 300)
plot(1:5)
dev.off()
This saves to disk, which you said you wanted to avoid, but you can always delete it again later (programatically even, with file.remove).
I'd also like to make the case that when you copy and paste, your work isn't as easily reproducible as when you use code. There is no trace of what you have done, and when your data changes, you need to go through the rigmarole of clicking again, rather than just executing your updated script.