Error in plot.new() : figure margins too large, Scatter plot

后端 未结 7 1797
囚心锁ツ
囚心锁ツ 2020-11-29 16:26

I\'ve looked in different questions for a solution and I\'ve tried what was suggested but I have not found a solution to make it work.

Everytime I want to run this c

相关标签:
7条回答
  • 2020-11-29 16:28

    If you get this message in RStudio, clicking the 'broomstick' figure "Clear All Plots" in Plots tab and try plot() again.

    Moreover Execute the command

    graphics.off()
    
    0 讨论(0)
  • 2020-11-29 16:32

    Just a side-note. Sometimes this "margin" error occurs because you want to save a high-resolution figure (eg. dpi = 300 or res = 300) in R.
    In this case, what you need to do is to specify the width and height. (Btw, ggsave() doesn't require this.)

    This causes the margin error:

    # eg. for tiff()
    par(mar=c(1,1,1,1))
    tiff(filename =  "qq.tiff",
         res = 300,                                                 # the margin error.
         compression = c( "lzw") )
    # qq plot for genome wide association study (just an example)
    qqman::qq(df$rawp, main = "Q-Q plot of GWAS p-values", cex = .3)
    dev.off()
    

    This will fix the margin error:

    # eg. for tiff()
    par(mar=c(1,1,1,1))
    tiff(filename =  "qq.tiff",
         res = 300,                                                 # the margin error.
         width = 5, height = 4, units = 'in',                       # fixed
         compression = c( "lzw") )
    # qq plot for genome wide association study (just an example)
    qqman::qq(df$rawp, main = "Q-Q plot of GWAS p-values", cex = .3)
    dev.off()
    
    0 讨论(0)
  • 2020-11-29 16:38

    Just clear the plots and try executing the code again...It worked for me

    0 讨论(0)
  • 2020-11-29 16:44

    Every time you are creating plots you might get this error - "Error in plot.new() : figure margins too large". To avoid such errors you can first check par("mar") output. You should be getting:

    [1] 5.1 4.1 4.1 2.1
    

    To change that write:

    par(mar=c(1,1,1,1))
    

    This should rectify the error. Or else you can change the values accordingly.

    Hope this works for you.

    0 讨论(0)
  • 2020-11-29 16:47

    Invoking dev.off() to make RStudio open up a new graphics device with default settings worked for me. HTH.

    0 讨论(0)
  • 2020-11-29 16:49

    Just run graphics.off() before plotting your data. This instruction solved my error. So, it's harmless to try it before taking a more complex solution.

    0 讨论(0)
提交回复
热议问题