figurePanel: Make a figure panel with title

View source: R/figurePanel.R

figurePanelR Documentation

Make a figure panel with title

Description

Make a figure panel with title

Usage

figurePanel(gg, title)

Arguments

gg

A grob object

title

Character, title of the plot panel, e.g. A, (B), etc.

Value

A grob object

Examples


require("ggplot2")
df <- data.frame(
  gp = factor(rep(letters[1:3], each = 10)),
  y = rnorm(30)
)

ds <- do.call(rbind, lapply(split(df, df$gp), function(d) {
  data.frame(mean = mean(d$y), sd = sd(d$y), gp = d$gp)
  }))
  
g1 <- ggplot(df, aes(gp, y)) +
  geom_point() +
  geom_point(data = ds, aes(y = mean), colour = 'red', size = 3)
  
g2 <- ggplot() +
  geom_point(data = df, aes(gp, y)) +
  geom_point(data = ds, aes(gp, mean), colour = 'red', size = 3) +
  geom_errorbar(
    data = ds,
    aes(gp, mean, ymin = mean - sd, ymax = mean + sd),
    colour = 'red',
    width = 0.4
  )
  
panelA <- figurePanel(g1, "(A)")
panelB <- figurePanel(g2, "(B)")
layoutMat <- matrix(c(1,2), nrow=1)
gridExtra::grid.arrange(grobs=list(panelA, panelB),
 layout_matrix=layoutMat)


bedapub/ribiosPlot documentation built on Sept. 1, 2023, 6:50 p.m.