I use R in Mac through command line. When I need to draw some plot, R open plotting device called Quartz to display plot. It all works fine, but problem arise when I update a plot or draw a new plot based on changed plot. It looks like Quartz device does not automatically update the same. I need to close Quartz before I update my data and hit enter, so that new/modified plot can appear in Quartz.
I am wondering if this is default behaviour when R is run from command line in Mac? Is there any way to automatically update the plot in Quartz every time I update the data for plotting?
Any pointer will be highly appreciated.
Related
I am working on a ggplot graph to be used within PowerBI. I would like to use Cairo to improve the look of the graph. When using the CairoWin() function in RStudio it generates a popout window. The same happens in PowerBI. This is no good for the PowerBI dashboard as I need the Cairo generated graph to remain embedded in the dashboard replacing the current ggplot graph not as a popout.
I have tried the Cairo documentation but, no luck. Is there anyway for Cairo to replace the ggplot generated graph instead of creating a popout window?
Create a plot with cars dataset and attribute speed along the X axis and distance in y axis .
Label the axes.
I have done this programming still there is some problem:
plot(cars,xlab="speed",ylab="distance")
Even though everything seems correct the terminal doesn't move to the next part
What environment are you using? I was able to execute the following code and produce the plot you want using both RStudio and R directly in the terminal.
library(MASS)
plot(cars, xlab="Distance", ylab="Speed")
If you're running straight from the terminal then you'll need to specify a window to pop up. The following question has an answer that outlines what to do depending on your operating system:
How to pop up the graphics window from Rscript?
So, for example, if you don't have your system configured to automatically open the plot window, and you're running on a mac, the following code will produce what you want directly from running R in the terminal:
library(MASS)
X11()
plot(cars, xlab="Distance", ylab="Speed")
How do you delete the current (but not all) plots in the RStudio plotting device?
dev.off() will remove all plots, but what if I just want to remove one? I don't want to have to press that red 'x' button because I want to remove one plot without pressing a button.
In R, you would just use dev.new() before each plot, so you dev.off() to only clear the last plot.
In RStudio, you can use x11(), windows() or quartz() (depending on your device) before each plot. Then call dev.off() to clear last plot. You can also use dev.set() to choose specific plots that way.
If your question is specifically asking to delete the last plot within the same RStudio window (rather than making new windows), not sure if it's possible, since RStudio treats that window as one device. An idea would be to look at a way to call the C++ function removePlot() in the RStudio project.
I found in the Github repository for RStudio the C++ code:
display.removePlot(display.activePlotIndex());
You could output the plots and manage the files that way.
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.
I am completely new to projectR but I have tried to find a way to simply add a new graphical frame (window) to plot another plot but at the same time keep my exising plot in the other window. SOmething like just do "figure" in matlab.
I am running on Linux
You mean you want to open a new device -
dev.new() - will open the device.
Then the plot you will create will be on this device.