layer_na_rle: Add a layer of 'list_of_na_rle()' to an existing ggplot

Description Usage Arguments Examples

View source: R/plot.R

Description

Add a layer of list_of_na_rle() to an existing ggplot

Usage

1

Arguments

var

A variable that contains list_of_na_rle().

data

A data frame.

...

Passed to ggplot2::geom_rect().

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
if (!requireNamespace("nycflights13", quietly = TRUE)) {
  stop("Please install the nycflights13 package to run these following examples.")
}
library(dplyr, warn.conflicts = FALSE)
weather <- nycflights13::weather
na_runs_wind <- weather %>% 
  group_by(origin) %>% 
  summarise_at(
    vars(contains("wind")), 
    ~ list_of_na_rle(., index_by = time_hour)
  )

library(ggplot2)
ggplot(weather, aes(x = time_hour, y = wind_gust)) +
  geom_line(na.rm = TRUE) +
  layer_na_rle(wind_gust, data = na_runs_wind, fill = "red", alpha = .5) +
  facet_grid(origin ~ .)

earowang/mists documentation built on Sept. 21, 2019, 1:12 p.m.