1
votes

I have 24 boxplots, each of it comparing an environmental parameter from two different sites. I like to plot them in one figure with 4 plots in the first row, 5 plots in the second row, 5 plots in the third row, 6 plots in the fourth row and 4 plots in the fifth row. This order is of importance, as by this each row contains a set of related parameters, e.g. abiotic parameters like median grain size, sediment porosity, water content etc.

My approach was to use the split.screen function:

split.screen(c(4,1)) 
# [1] 1 2 3 4 
split.screen(c(1,4), screen=1) 
# [1] 5 6 7 8
split.screen(c(1,5), screen=2)
# [1] 9 10 11 12 13
split.screen(c(1,5), screen=3)
# [1] 14 15 16 17 18
split.screen(c(1,6), screen=4)
# [1] 19 20 21 22 23 24
split.screen(c(1,4), screen=5)
# [1] 25 26 27 28

Then I start to include the plots:

screen(5)
boxplot(Data$Parameter1 ~ Data$Sites)
screen(6)
boxplot(Data$Parameter2 ~ Data$Sites)

and so on

Until the fourth row it is working, but when I like to add the first plot of the fifth row

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

appears.

I already sized up the plot-window to the maximum on my screen following suggestions from: Error in plot.new() : figure margins too large in R

and made the margins smaller following suggestions from: Error in plot.new() : figure margins too large, Scatter plot

using

par(mar=c(0.1,0.1,0.1,0.1)

but nothing worked out. I assume, that the size of my plot-window is to small to display the entire figure (even if I maximise the size). Therefore, I like to ask:

Is there a way to create such a figure without showing it in the plot-window?

Please be aware that I am not an R expert, not familiar with ggplot and not a coder. Therefore, if you have a solution for my problem, please explain it logically comprehensible and like you would explain it to a 9-years-old - that works quite good for me. Thank you for the effort in advance.

2
If you are using Rstudio, it could be that the windows size for plots is very small. You can open an external plotting window by calling x11().Vandenman

2 Answers

1
votes

You can create figures without using the plot window by using the png command, From the doumentation:

png(file = "myplot.png", bg = "transparent")
plot(1:10)
rect(1, 5, 3, 7, col = "white")
dev.off()

by using the width and height parameters to png you can make very large images. Here is a link to the documentation

1
votes

The following code works on my R and RStudio:

split.screen(c(4,1)) 
split.screen(c(1,4), screen=1) 
split.screen(c(1,5), screen=2)
split.screen(c(1,5), screen=3)
split.screen(c(1,6), screen=4)
split.screen(c(1,4), screen=5)

for (k in 6:28) {
  screen(k)
  par(mar=c(2,2,0.1,.1), oma=rep(0,4))
  boxplot(iris$Sepal.Length ~ iris$Species)
  text(.35,7.5,k, col="red", pos=4)
}   
close.screen(all=T)

enter image description here