76

I set par(mfrow =c(1,2)) and now everytime I plot it shows splits it into 2 plots. How can I reset this to only show one plot.

Thanks so much.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
akz
  • 1,865
  • 2
  • 16
  • 13

3 Answers3

110

You can reset the mfrow parameter

par(mfrow=c(1,1))
Karsten W.
  • 17,826
  • 11
  • 69
  • 103
  • 9
    @akz More generally, keep in mind that each plotting device has it's own separate `par` settings. So if you are generating plots interactively in the console and you change some settings using `par(foo = bar)`, you can always start over by calling `dev.off()` and create plots on a new device. – joran Sep 24 '11 at 03:57
  • that's super useful. Thanks Joran. – akz Sep 24 '11 at 18:27
  • 7
    another useful idiom is `oldparams <- par(mfrow=c(2,1)); [do stuff]; par(oldparams)` – Ben Bolker Sep 24 '11 at 21:05
  • 1
    Just a heads up for anyone trying this in a R script. Sometimes there will be functions (e.g. `NbClust`) which will generate graphs for you, they actually change the value of `mfrow` and leave it; therefore your next graphs will be side-by-side. Just add `par(mfrow=c(1, 1))` after running those functions and you're good to go. – Carlos F Nov 15 '19 at 14:30
41

You can reset the plot by doing this:

dev.off()
eebbesen
  • 5,070
  • 8
  • 48
  • 70
Lean
  • 411
  • 4
  • 2
  • 8
    This works when working interactively but can break document generation systems like knitr\pandoc. – DLKJ Jul 21 '14 at 14:46
  • 2
    If you do not check if there is anything to close, you will have an error. It is better to use: `if(dev.cur() > 1) dev.off()` – Antoni Nov 22 '20 at 16:11
  • We can use `graphics.off()` to close all devices at once. – jay.sf Apr 20 '22 at 19:37
0

Both dev.off() and graphics.off() works fine for me. Good luck!