Learn R Programming

miscset (version 0.4)

ggplotlist: Arrange a List of ggplots

Description

Arrange a list of ggplots with grid.arrange and output on local graphic device or as pdf/png when a path is supplied.

Usage

ggplotlist(x, ncol = 1, path, width = 11, height = 8)

Arguments

x
A list containing at least one ggplot object of class gg.
ncol
Number of columns in the grid.
path
Optional. A character string that gives the path to export the plot to a file, ending with 'pdf' or 'png' (case insensitive). If missing, then the grid is returned to the current graphic device.
height,width
A numeric value in inches for the size of the output file in case path is provided. Else ignored.

Examples

Run this code
#

library(ggplot2)
x <- list(
  ggplot(data.frame(a=1:5,b=1:5), aes(x=a,y=b,col=b)) + geom_line(),
  ggplot(data.frame(a=1:5,b=1:5), aes(x=a,y=b,shape=factor(b))) + geom_point())
ggplotlist(x, 2)

#

Run the code above in your browser using DataLab