I want to visualise all series in the example dataset airquality: Ozone, Solar.R, Temp and Wind. There are 2 ways to do it:
In 2 steps:
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]]
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")