reduce size of default Quartz / plot object - r

I have a laptop with low screen resolution. As a consequence, when I give a plot command in R the Quartz plot object runs off the screen.
Is it possible to change set some option -- preferably in my .Rprofile -- that will reduce the size of the default plot output when using interactive R?

?quartz
quartz.options(width=4, height=4)
(The default values are 7 and 7 which can eaisly be obtained by typing just:
quartz.options()[c("width", "height")] # .)

Related

Gnuplot: multiple plots in multiple windows

I want to do multiple plots related to differents data columns of the same file but I want a new window for each plot. I don't want attached plots associated to the command set multiplot layout 1,2.
The idea is represented by the following pseudocode:
>gnuplot
>plot "myfile.txt" u 1:4
>#make me plot another file without deleting the previous one i.e. open a new window on which data is plotted
>instructions I don't know
>plot "myfile.txt" u: ($3*$3)
>#I obtain two windows
You don't write which terminal you are using. I understand you want to have two windows next to each other, and not two graph as file on disk. In gnuplot console check for example: help wxt. In case you want two files on disk you have to select another terminal, e.g.
set term pngcairo
set output 'myOutput1.png'
plot x
set output 'myOutput2.png'
plot x**2
set output
So with the interactive wxt terminal the following works for me:
Code:
### several terminals
reset session
set term wxt 1 size 500,400
plot sin(x)
set term wxt 2 size 500,300
plot cos(x)
set term wxt 3 size 300,200
plot x**2
### end of code
Result:

How to download clear plot through rstudio?

I plot in rstudio, cannot see the number in plot, then I download as bigger size.
Whatever the png or jpeg format, even size is 2048 pixels, still cannot read the number in plot.
How to solve this problem?
RStudio has known sizing issue of saving pictures plotted in the "plots" window. What I would do is to save the picture directly in code.
Refer to this SO question
In short, what you can do is:
png(filename = pathToYourOutputPNG) # create a png device
plot() # write your plotting functions here
dev.off() # close the device

How to keep previous plots and windows in Gnuplot?

I have some problems of using gnuplot. I just begin with it.
(1)What is the command for keeping the previous plot when I plot new data? Do I have to plot the old data and the new data at the same time?
(2)What is the command for open a new window while keep the old ones? Do I have to set the window's id by using, e.g.,
set terminal wxt 3
, before each plot?
Can anyone give me some help or some good references?
Usually, to plot several data set you would use
plot 'data1.dat', 'data2.dat'
You could also use replot to add one of the data sets later
plot 'data1.dat'
...
replot 'data2.dat'
To open a new window, you must use the window's id like with set terminal wxt 2. The old windows stay open, but you cannot interact with them anymore (zooming, scrolling etc.). See also the discussion to the quesiton Two interactive windows in Gnuplot with wxt terminal.
You already wrote the answers of your questions.
1.: You can use the replot command:
plot sin(x)
replot cos(x)
but this just expands to
plot sin(x), cos(x)
So, it replots all data and does not just add the cos(x).
2.: Yes, you can also switch between the windows to update the plots. But note that settings like ranges and labels are not stored per window / plot, but globally. If they are different for different plots, you have to change them every time.
You may also have a look at "set multiplot" to put several plots on one window / picture. But it is not so nice for interactive plotting, as you will notice.
Also, output terminals supporting multiple pages like pdfcairo will add a new page for each plot.

How to get R plot window size?

How can I get the size of the plot window in R? I've been using xwininfo, but there must be a function or variable in R to extract the current plot height and width.
UPDATE
This works as a savePlot() replacement if you don't have Cairo support and you want to export plots to Windows or other 100 dpi devices:
dev.copy(png, "myplot.png", width=dev.size("px")[1], height=dev.size("px")[2],
res=100, bg="transparent")
dev.off()
You can use dev.size. Here is an example:
x11()
plot(1)
dev.size("in")
[1] 6.989583 6.992017
dev.size("cm")
[1] 17.75354 17.75972
This gets the size of your plotting window in inches and centimeters.
Similar for a png device:
png('kk.png')
dev.size("in")
[1] 6.666667 6.666667
Does this help you?
As mentioned , using some par settings you can control control the size and the location of the plot regions. But those parameters can be a little bit confusing.( at least for me), I tried to resume some of them in this plot precising the units of each parameter.
PS: the original graphics is adpated from Paul Murrel Book: R graphics.
You should have a look to par()$fin.
HTH

Plot to specific plot in multiple-plot window?

If I create a multi-plot window with par(mfrow=...), is it possible to send data to a specific plot (i.e. "the one in the lower left corner") or is the plotting always necessarily sequential? Is there a package for R that does something like this?
For those that are interested, this problem arises out of the fact that R is a single-threaded application and is not ideal for real-time visualization. I have multiple real-time data streams coming into R from an outside source that produces the data asynchronously (and therefore the data streams don't always come in the same order). This results in R flipping around the order of the data visualization plots every time it updates.
You could use split.screen():
par(bg = "white") # erase.screen() will appear not to work
# if the background color is transparent
# (as it is by default on most devices).
split.screen(c(2,1)) # split display into two screens
split.screen(c(1,3), screen = 2) # now split the bottom half into 3
screen(1) # prepare screen 1 for output
plot(10:1)
screen(4) # prepare screen 4 for output
plot(10:1)
Have a look at help(layout). This allows you to specify the what, where and in which sizes.
Once plotted, I don't think you re-plot just partially. But you you can use dev.set() et al to switch between different 'plot devices' (ie windows); see help(dev.list).
Note that the suggested answer here is to use split.screen(). It may work, but according to the split.screen help file: "The recommended way to use these functions is to completely draw a plot and all additions (i.e. points and lines) to the base plot, prior to selecting and plotting on another screen. The behavior associated with returning to a screen to add to an existing plot is unpredictable and may result in problems that are not readily visible."
In an answer to my question, there is a more useful solution, using the par(mfg) option:
Change plot panel in multipanel plot in R
Another option is that of implementing a little GUI e.g. with RGtk2 or RTclTk.
I generally do this for graphs that I want to change in realtime and it works great.
For instance, with RGtk2 and cairoDevice you could just do something like (I assume you have a Glade interface)
# Helper function to get a widget from the Glade interface
getWidget <- function(name)
{
return (interface$getWidget(name))
}
interface <- gladeXMLNew("interface.glade", root="mainWindow")
# Our cairo devices (to draw graphics).
# plot1, plot2, and plot3 are GtkDrawingArea widgets
asCairoDevice(getWidget("plot1"))
# dev.cur() will give the device number of the last device we created
# You'll use this to switch device when you draw in different plots
# Storing the device number is important because you may have other
# devices open from other unrelated plots
# (so never assume they'll just start from 1 and be sequential!!!)
plot1.dev <- as.integer(dev.cur())
asCairoDevice(getWidget("plot2"))
plot2.dev <- as.integer(dev.cur())
asCairoDevice(getWidget("plot3"))
plot3.dev <- as.integer(dev.cur())
# To draw in a specific plot you just do
dev.set(plot2.dev)
plot(....)
This has many other advantages, like that of being able to positions the graphs easily where you want (using Glade Interface Designer) and having the possibility of user interaction through specific buttons (e.g. you may have a "pause acquisition" button).

Resources