R/plot_hd.R

Defines functions plot.hd

#' @import ggplot2
#' @importFrom reshape2 melt
#' @import zoo
#' @method plot hd
#' @export

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

  Index <- NULL
  value <- NULL
  PlotData <- as.data.frame(x$hidec)
  if(inherits(x$hidec, "ts")){
    tsStructure = attr(x$hidec, which = "tsp")
    PlotData$Index <- seq(from = tsStructure[1], to = tsStructure[2], by = 1/tsStructure[3])

    PlotData$Index <- as.Date(yearmon(PlotData$Index))

  } else {
    PlotData$Index <- 1:nrow(PlotData)
    PlotData$V1 <- NULL
  }

  dat <- melt(PlotData,id = 'Index')
  ggplot(dat, aes(x = Index, y = value)) + geom_line() +
    facet_wrap(~variable, ncol = 1) +
    xlab("Time") + theme_bw()

}
alexanderlange53/svars documentation built on Jan. 31, 2023, 7:50 a.m.