0

I created 4 different plots in base R and now I want to put them together in one page as a report. I tried using gridGraphics and then ggarrenge but the plots have their labels cut. Is there a simpler way to do this in base R or with another library?

Just adding the code I tried for this

par(mar=c(4, 6, 4, 6) + 0.1,cex.axis=0.8)#START A NEW PLOT FRAME

  plot(nox_day$date,nox_day$nox,pty='s',xaxt='n',#CALL THE DESIRED VARIABLES
        xlim=period,ylim=c(0,max(nox_day$nox,na.rm = T)),#SET LIMITS OF X AND Y AXIS
        xlab='', ylab='',
        col=color_pal[1],
        axes=F, main='',
        cex=0.5,las=1)
  axis(2, ylim=c(0,max(nox_day$nox,na.rm = T)),
       col='black',lwd=0.2,cex = 0.8,las=1)
  mtext(2,text='NOx (ppb)',line=2,
        col=color_pal[1],cex = 0.8,las=0)

  par(new=T) #START A NEW PLOT OVER THE DAME FRAME
  plot(spectronus_day$et, spectronus_day$co, pty='s',
       xlim=period,ylim=c(0,max(spectronus_day$co,na.rm = T)),#SET LIMITS OF X AND Y AXIS
       xlab='', ylab='',
       col=color_pal[2],
       main='',cex=0.5,yaxt='n',ann = FALSE,xaxt='n')
  mtext(4,text='CO (ppb)',line=3,
        col = color_pal[2],
        cex = 0.8,las=0)
  axis.POSIXct(1,nox_day$date,at = hours,format = '%H:%M')
  rug(hours, ticksize = -0.01, side = 1)#create minor breaks
  rug(days,ticksize = -0.02,side=1) #create day breaks
  grid.echo()
nox_co_plot <- grid.grab()#save the plot as ana object.

For each plot a similar code and then

ggarrange(biogenics_PAR_plot,org_bc_plot,Inorg_plot,nox_co_plot,
      ncol=2,nrow=2, align = "v")
Jhonathan
  • 365
  • 1
  • 9
  • 1
    See the answer for base graphics in the duplicate. Note that ggplot uses grid graphics rather than base graphics so solutions that work for ggplot will not work for base graphics. For base you would either use `par(mfrow=)` or use the `layout()` function for even more control. – MrFlick Feb 17 '20 at 02:49
  • Thanks, I found what I want with the layout function. – Jhonathan Feb 17 '20 at 05:35

0 Answers0