R/plotcosmosts.R

Defines functions plot.cosmosts

Documented in plot.cosmosts

#' Plot generated Timeseries
#'
#' Visualizes Timeseries generated by the package CoSMoS.
#'
#' @param x \code{\link{fitactf}} result object
#' @param ... other arguments
#'
#' @export
#' @method plot cosmosts
#' @import ggplot2 data.table
#'
#' @examples
#'
#' library(CoSMoS)
#'
#' ## generate TS
#' ts <- generateTS(margdist = 'ggamma',
#'                  margarg = list(scale = 1,
#'                                 shape1 = .8,
#'                                 shape2 = .8),
#'                  acsvalue = acs(id = 'paretoII',
#'                                 t = 0:30,
#'                                scale = 1,
#'                                 shape = .75),
#'                  n = 1000,
#'                  p = 30,
#'                  TSn = 2)
#'
#' ## plot the TS
#' plot(ts)

plot.cosmosts <- function(x, ...) {

  dta <- data.table(n = seq_along(x[[1]]),
                    do.call(cbind, x))

  names(dta)[2:(length(x) + 1)] <- paste('timeseries', 1:length(x), sep = '_')

  m.dta <- melt(data = as.data.table(x = dta),
                id.vars = 'n')

  p <- ggplot(data = m.dta,
              mapping = aes(x = m.dta$n,
                            y = m.dta$value)) +
    geom_col() +
    labs(x = '',
         y = 'value') +
    facet_wrap(~variable, ncol = 1) +
    theme_gray() +
    theme(legend.position = 'bottom',
          strip.background = element_rect(fill = 'grey5'),
          strip.text = element_text(colour = 'grey95'))

  return(p)
}

Try the CoSMoS package in your browser

Any scripts or data that you put into this service are public.

CoSMoS documentation built on May 30, 2021, 1:06 a.m.