I want to visualise all series in the example dataset airquality: Ozone, Solar.R, Temp and Wind. There are 2 ways to do it:

Call ggplot many times with lapply

In 2 steps:

  1. Create a function that plots a given variable.
  2. Apply this function to all interesting column in the dataset.
library(ggplot2)
#' @param yvar character name of the y variable
plotserieslines <- function(yvar){
    ggplot(airquality, aes_(x=~Day,y=as.name(yvar))) +
        geom_line() +
        facet_wrap(~Month)
}
lapply(names(airquality[c(1:4)]), plotserieslines)
## [[1]]

## 
## [[2]]

## 
## [[3]]

## 
## [[4]]

Reshape the table in long format and call ggplot only once

library(tidyr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
airquality %>% 
    gather(key, value, -Month, -Day) %>% 
    ggplot(aes(x = Day, y = value)) +
    geom_line() +
    facet_grid(key ~ Month, scales = "free")