Make R Studio plots only show up in new window

前端 未结 5 477
鱼传尺愫
鱼传尺愫 2021-02-08 19:26

When using R Studio, I usually just work with an .R file stacked on top of the Console. I keep the other panes (Environment, History, Files, etc) hidden.

But whenever I

相关标签:
5条回答
  • 2021-02-08 19:54

    The dev.new() function will open a new plot window, which then becomes the target for all plots.

    If you wish to open another window you can run the command a second time to open a second window.

    dev.off() will shut down the window (in the order they were opened by default).

    You can see how to control multiple graphics devices in the documentation here.

    0 讨论(0)
  • 2021-02-08 19:56

    In RStudio, the default graphics device is normally "RStudioGD". You can change that to something else: the normal choices are "windows" on Windows, "quartz" on MacOS, "X11" on Linux. So for example, use

    options(device = "quartz")
    

    in your RStudio session on a Mac and you'll get the regular MacOS graphics window.

    0 讨论(0)
  • 2021-02-08 20:01

    Try using the windows command before your plot call.

    windows();(mpg ~ wt, mtcars)
    

    The plot should pop-up in its own window whilst the pane stays minimized.

    0 讨论(0)
  • 2021-02-08 20:01

    You can force RStudio to show plots in the Source window if you use R Markdown. In a Rmd file, plots are shown together with code; it's called an R Markdown notebook. You can set the size of the plots too, in what is called an R code chunk:

    ```{r fig.height = 2, fig.width = 3}
    plot(mpg ~ wt, mtcars)
    ```
    

    When you run the chunk, the plot is shown below it.

    If you want to set the plot size for the whole notebook, set the package option using opts_knit and opts_chunk, for example:

    ```{r setup} 
    library(knitr) 
    opts_knit$set(global.par = TRUE) 
    opts_chunk$set(fig.width = 4.5, fig.height = 3.5)
    ```
    

    For more information, see here and here.

    0 讨论(0)
  • 2021-02-08 20:17

    Commenting the following lines in "RStudio\R\Tools.R" seems to work...

    # set our graphics device as the default and cause it to be created/set
    .rs.addFunction( "initGraphicsDevice", function()
    {
       # options(device="RStudioGD")
       # grDevices::deviceIsInteractive("RStudioGD")
      grDevices::deviceIsInteractive()
    })
    
    0 讨论(0)
提交回复
热议问题