#' Plot a SUMs File
#'
#' @param data a sumsarizer formatted data table for one sensor mission
#' @param events a table of events as generated by \code{\link{list_events}}.
#' If \code{NULL}, will be generated automatically from the \code{label} column of \code{data}
#' @import ggplot2
#' @importFrom lubridate floor_date
#' @export
plot_sums <- function(data, events = NULL){
if(is.null(events)){
events <- list_events(data)
}
data$week <- as.character(floor_date(data$timestamp, "week"))
events$week <- as.character(floor_date(events$start_time, "week"))
min_value <- min(data$value)
max_value <- max(data$value)
value_range <- max_value - min_value
min_value <- min_value - value_range*0.1
max_value <- max_value + value_range*0.1
ggplot(data,aes_string(x="timestamp",y="value",group=1))+geom_line()+
xlab("Timestamp")+ylab("Value")+
geom_rect(data=events,aes(x=NULL, y=NULL,
xmin=start_time,xmax=stop_time,
ymin=min_value,ymax=max_value),
fill="red",
alpha=0.5)+facet_wrap(~week,ncol=1,scales="free_x")+scale_x_datetime(expand=c(0,0))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.