move_facet_strip_y: Move facet strip y

Description Usage Details Value Examples

Description

A brutish fix to allow plotting of time series stacked on top of each other. It will work for more than just time series. Probably violates a few principles of the grammar of graphics and usually requires the violation of tidy data principles.

Usage

1
2
3
move_facet_strip_y(object, sane.defaults = TRUE)

move_facet_strip_x(object, sane.defaults = TRUE)

Details

takes ggplot object and changes it to a grob, mauls it a bit, and spits out a grob From: http://stackoverflow.com/questions/23497682/alter-facet-grid-output-in-ggplot2

Value

grid object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(reshape2)
## simulate a model study
air <- transform(airquality, Ozone.model = Ozone +
    rnorm(length(Ozone), 2),
                        Wind.model = Wind + rnorm(length(Wind)))
## Add time, see ?airquality
air$dtm <- as.Date(paste("1973", air$Month, air$Day,
                                sep = "-"), format="%Y-%m-%d", tz="EST")
d.f <- melt(air, id.vars = "dtm", measure.vars = c("Wind",
    "Wind.model", "Ozone", "Ozone.model"))
d.f$type <- ifelse(grepl("model", d.f$variable), "Modeled", "Measured")
d.f$Variables <- sub("\\.model", "", d.f$variable)
(box <- ggplot(d.f, aes(dtm, value, color=type)) +
    geom_line() +
     facet_grid(Variables~., scales="free_y"))
## please note that \code{ggsave} will no longer work with earlier  versions (<= 2.0.0) of ggplot2
x11()
move_facet_strip_y(box)

oneyb/ggcrap documentation built on May 24, 2019, 2:24 p.m.