35

RStudio is not showing the generated plots in the plot pane anymore. Instead they open in a separate file with the name "Quartz". Here's my session info.:

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.9.5 (Mavericks)

locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] cluster_2.0.4 tm_0.6-2      NLP_0.1-9     ggplot2_2.1.0

loaded via a namespace (and not attached):
 [1] colorspace_1.2-6 scales_0.4.0     plyr_1.8.4       parallel_3.3.1   tools_3.3.1      gtable_0.2.0     Rcpp_0.12.5      slam_0.1-35     
 [9] grid_3.3.1       munsell_0.4.3   

I tried tools > global options > panes > plots is selected.

I don't know what other info to share. I can see the plot pane with "plots" tab active. But it's blank.

Screen:

Notice the new menu with "Quartz" appear. Not sure what this is, but it comes up when R generates the plot and the usual RStudio menu disappears.

How do I get RStudio to display plots in the plots pane?

M--
  • 25,431
  • 8
  • 61
  • 93
Doug Fir
  • 19,971
  • 47
  • 169
  • 299
  • 1
    You might try re-installing / updating rstudio, but it's unclear this will fix it. As a first step. quit (`command + q`) rstudio and restart it to see if that helps. – lmo Jun 28 '16 at 12:29
  • 1
    HI, I did re-instal and this seems to have corrected the problem. Leaving the question open in case anyone else knows why rstudio did this and how to fix – Doug Fir Jun 29 '16 at 01:20

10 Answers10

51

Try running this:

dev.off()

Check if it works:

plot(rnorm(50), rnorm(50))
M--
  • 25,431
  • 8
  • 61
  • 93
mkearney
  • 1,266
  • 10
  • 18
  • 16
    HI, "Error in dev.off() : cannot shut down device 1 (the null device)" – Doug Fir Jun 28 '16 at 07:33
  • 3
    Would be nice if someone explains what `dev.off()` does and in which situations it actually helps. I had to call `dev.off()` several times to get R Studio showing plots again. – normanius Nov 28 '21 at 19:31
  • Sometimes you want to send files to different places in R (usually saving figures to local files!). dev.off() tells R you are done dumping data to that file location. – RegressForward May 04 '22 at 15:25
20

I am working with Rmarkdown, and in my case I solved this problem like this:

  1. Go to Tools->Global Options->Rmarkdown

  2. In "Show output preview in" select "Viewer Pane"

  3. Uncheck the box "Show output inline for all R Markdown documents"

M--
  • 25,431
  • 8
  • 61
  • 93
Juan
  • 217
  • 2
  • 2
10

Follow below procedure to resolve the issue.

dev.off()
print(plot(1)) # Basically use print command once

now use plot command as you normally use and should work fine.

M--
  • 25,431
  • 8
  • 61
  • 93
Tokci
  • 1,220
  • 1
  • 23
  • 31
8

For me, it worked when I first closed all the devices @udit-gupta. Recursively closing all the devices after finding the devices.

dev.cur()
dev.off(i) #where i = index of device to be switched off

get the device back with

getOption("device")

or

dev.set(which = dev.next())
M--
  • 25,431
  • 8
  • 61
  • 93
Kiran K Telukunta
  • 2,178
  • 3
  • 20
  • 19
4

I was able to visualize plots in the plot pane for a while before it vanished. All the attempts with the suggestions above failed. What is referred in the blog below got it working.

https://datasciencelearner.wordpress.com/2014/08/17/my-plot-is-not-showing-up/

The trick is to wrap the graphics command inside print function, for instance:

print(
    plt2 <- ggplot(housing,
               aes(x = Home.Value)) +
                  geom_histogram()
)
M--
  • 25,431
  • 8
  • 61
  • 93
KaLi
  • 149
  • 1
  • 4
3

I had the same problem after updating R to version 3.3.2 and using RStudio 0.98.0. Installing the latest version of RStudio fixed the problem.

M--
  • 25,431
  • 8
  • 61
  • 93
mwithiiri
  • 47
  • 1
2

I had the same problem and none of the above solutions fixed the issue. I completely uninstalled the Rstudio and installed it again and only after that the Rstudio started to show my plots in the plot pane again.

Amin Shn
  • 532
  • 2
  • 11
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 06 '22 at 10:51
0

It could be because graphic device are already on .

To find indices of open devices:

dev.cur()

To close devices:

dev.off(i)

where i is index of device to be switched off.

M--
  • 25,431
  • 8
  • 61
  • 93
UDIT GUPTA
  • 39
  • 1
0

enter dev.off() command and Enter, it will fix the problem.

-1
  1. Go to "view" on the menu bar.
  2. Select "panes".
  3. Mark "all panes".
double-beep
  • 5,031
  • 17
  • 33
  • 41