Errors with par() and plot() in RStudio

299 Views Asked by At
par(mfrow = c(2,1))
plot(pressure$pressure~pressure$temperature)
curve((0.168 + 0.007*x)^(20/3), from = 0, to = 400, add = TRUE)
plot(pressure$pressure^(3/20)~pressure$temperature)
abline(0.168,0.007)

Above is the code. They will run normally in R, but report errors in RStudio. I have tried reinstall the latest RStudio but the errors persist. Here are the errors in RStudio:

> par(mfrow = c(2,1))
> plot(pressure$pressure~pressure$temperature)
Error in plot.new() : figure margins too large
> curve((0.168 + 0.007*x)^(20/3), from = 0, to = 400, add = TRUE)
Error in plot.xy(xy.coords(x, y), type = type, ...) : 
  invalid graphics state
> plot(pressure$pressure^(3/20)~pressure$temperature)
Error in plot.new() : figure margins too large
> abline(0.168,0.007)
Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) : 
  invalid graphics state

Below is my sessioninfo:

> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Traditional)_Taiwan.950 
[2] LC_CTYPE=Chinese (Traditional)_Taiwan.950   
[3] LC_MONETARY=Chinese (Traditional)_Taiwan.950
[4] LC_NUMERIC=C                                
[5] LC_TIME=Chinese (Traditional)_Taiwan.950    
system code page: 65001

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

loaded via a namespace (and not attached):
[1] compiler_4.1.2 tools_4.1.2

Upon some search on the forum, I tried the following:

> par("mar")
[1] 5.1 4.1 4.1 2.1
> par(mar=c(1,1,1,1))
> par(mfrow = c(2,1))
> plot(pressure$pressure~pressure$temperature)
> curve((0.168 + 0.007*x)^(20/3), from = 0, to = 400, add = TRUE)
> plot(pressure$pressure^(3/20)~pressure$temperature)
> abline(0.168,0.007)

It will run and produce a plot that is not as desired (It looks a bit weird in terms of zoom levels): 1

As a comparison, here is the plot from R with the same codes: 2

Anyone could help to let the RStudio produce the same plot as R? Thanks!

1

There are 1 best solutions below

0
Hsin On

I changed the system scale level in the settings (I'm using Windows 10) from 150% to 100%. Then the errors are gone. Thanks all!