Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot in RStudio and not have a new window pop up (R Graphics: Device (ACTIVE)?

Tags:

plot

r

rstudio

Whenever I plot any plot in RStudio, I get a new device window that pops up. This was not always the case. I must have changed some settings. How do I change the settings back to have plots go to the RStudio plot window?

I have explored the dev.off() and other dev functions without success. For example:

# Clear workspace
rm(list=ls())

# create data
set.seed(1)
x <- rnorm(100, 0, 1)
y <- rnorm(100, 3, 1)

plot(x,y)

produces the popped up window in the screenshotted image: enter image description here

I want the device to stay in the RStudio plot window in the lower righthand corner. Does anyone have any help? I saw a similar question here that claims that an update will fix the issue. I updated within the last week. When I use sessionInfo() I am running R version 3.3.2, what I believe to be the latest version of R.

like image 913
Phil Avatar asked Nov 18 '16 16:11

Phil


People also ask

How do I clear my graphics in R?

This is equivalent to click on the button clear all plots in the plots panel. This is identical to Ctrl+L or to click on the clear console within the Edit menu. This is equivalent to click on the button clear objects from the workspace in the environment panel.

What does plot new do in R?

Description. This function ( frame is an alias for plot. new ) causes the completion of plotting in the current plot (if there is one) and an advance to a new graphics frame. This is used in all high-level plotting functions and also useful for skipping plots when a multi-figure region is in use.


2 Answers

I know that this has been answered but the problem can arise in multiple ways. My issue had been much simpler. The plots were not showing up in the Rstudio plot pane simply because the default null GD was turned off via dev.off(). I'm running Rstudio Version 1.1.442 with R Version R-3.4.4

I ran dev.off() a few times until all windows including hidden ones were closed and I received the following response in the console window.

null device 1

I then ran this and the plot appeared in the RStudio plot pane

dev.new()
plot(mtcars$mpg~mtcars$disp)
like image 75
George Avatar answered Sep 19 '22 09:09

George


For others who like me may still encounter this issue:

This is probably caused by an R update to 3.3.2 and is fixed by installing a newer version of RStudio. In my case 1.0.136 did the trick.

like image 26
puslet88 Avatar answered Sep 20 '22 09:09

puslet88