#' @title Layouts
#'
#' @description Different layouts for different plots
#'
#' @param title Create a space for titles. 2 for ylab, 3 or for main.
#'
#' @export NPlotsLayout
#' @export Layout0
#' @export Layout2
#' @export Layout6
#' @export Layout12
#' @export LayoutNarrow
#'
#' @examples
#' NPlotsLayout(5)
#' for(i in 1:5)plot(rnorm(100), type="l", ylab=i)
#'
#' Layout12(2)
#' for(i in 1:12){
#' plot(rnorm(10), type="l", ylab=i, axes=FALSE)
#' box(fg = gray(0.5)); axis(2, fg = gray(0.5), col=gray(0.5))
#' }
#'
# n number of vertical plots
NPlotsLayout <- function(n, withTitleSpace = FALSE){
par(mfrow=c(n,1), mar=c(0,4,0,0) + 0.1, oma=c(2,1,ifelse(withTitleSpace, 4,2),1))
}
#' @describeIn NPlotsLayout Default Layout
Layout0 <- function(){ par(mfrow=c(1,1), mar=c(5,4,4,2), oma=c(0,0,0,0))}
#' @describeIn NPlotsLayout Layout for 2 plots
Layout2 <- function(title=0){
if (title == 2){
par(mfrow=c(1,2), mar=c(0,4,0,0), oma=c(2,0,3,1))
} else if (title == 3){
par(mfrow=c(1,2), mar=c(0,0,4,0), oma=c(2,3,1,1))
} else {
par(mfrow=c(1,2), mar=c(0,0,0,0), oma=c(2,3,3,1))
}
}
#' @describeIn NPlotsLayout Layout for 6 plots
Layout6 <- function(title=0){
if (title == 2){
par(mfrow=c(2,3), mar=c(0,4,0,0), oma=c(2,0,3,1))
} else if (title == 3){
par(mfrow=c(2,3), mar=c(0,0,4,0), oma=c(2,3,1,1))
} else {
par(mfrow=c(2,3), mar=c(0,0,0,0), oma=c(2,3,3,1))
}
}
#' @describeIn NPlotsLayout Layout for 12 plots
Layout12 <- function(title=0){
if (title == 2){
par(mfrow=c(3,4), mar=c(0,4,0,0), oma=c(2,0,3,1))
} else if (title == 3){
par(mfrow=c(3,4), mar=c(0,0,4,0), oma=c(2,3,0,1))
} else {
par(mfrow=c(3,4), mar=c(0,0,0,0), oma=c(2,3,3,1))
}
}
#' @describeIn NPlotsLayout Narrow margin
LayoutNarrow <- function() par(mfrow=c(1,1), mar=c(2,2,2,1) + 0.1, oma=c(0,0,0,0))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.