Learn R Programming

dycdtools (version 0.4.4)

plot_ts: Time series plot of simulated and observed values at target depths. This function is based on ggplot2, and users can treat the object of this function in the same way as a ggplot2 object.

Description

Time series plot of simulated and observed values at target depths. This function is based on ggplot2, and users can treat the object of this function in the same way as a ggplot2 object.

Usage

plot_ts(
  sim,
  obs,
  target.depth,
  sim.start,
  sim.end,
  plot.start,
  plot.end,
  min.depth,
  max.depth,
  by.value,
  ylabel
)

Value

This function returns a ggplot object that can be modified with ggplot package functions.

Arguments

sim

a matrix of simulated variables. This matrix can be generated by running the "interpol" function.

obs

a data frame having three columns to describe observed values of a water quality variable. These three columns are 'Date' (as '%Y-%m-%d'), 'Depth', and the designated variable name which can be found from the var.name column of 'data(output_name)'. An example of such a data frame can be found with 'data(obs_temp)'

target.depth

a vector of depth (unit:m) for which time series simulation results will be plotted.

sim.start, sim.end

the start and end dates of the simulation period of the DYRESM-CAEDYM model run of interest. The date format must be "%Y-%m-%d".

plot.start, plot.end

the start and end dates of the period to be plotted in the format of "%Y-%m-%d".

min.depth, max.depth, by.value

minimum and maximum depths in the profile plot at an increment of by.value.

ylabel

the y axis title of the time series plot.

Examples

Run this code
 var.values<-ext_output(dycd.output=system.file("extdata", "dysim.nc",
                                                 package = "dycdtools"),
                       var.extract=c("TEMP"))

 for(i in 1:length(var.values)){
   expres<-paste0(names(var.values)[i],"<-data.frame(var.values[[",i,"]])")
   eval(parse(text=expres))
  }

# interpolate temperature for depths from 0 to 13 m at increment of 0.5 m
  temp.interpolated<-interpol(layerHeights = dyresmLAYER_HTS_Var,
                             var = dyresmTEMPTURE_Var,
                             min.dept = 0, max.dept = 13, by.value = 0.5)

 data(obs_temp)
# time series plot of temperature sim and obs
 p <- plot_ts(sim = temp.interpolated,
              obs = obs_temp,
              target.depth=c(1,6),
              sim.start="2017-06-06",
              sim.end="2017-06-15",
              plot.start="2017-06-06",
              plot.end="2017-06-15",
              ylabel="Temperature \u00B0C",
              min.depth=0,
              max.depth=13,
              by.value=0.5)

 p

Run the code above in your browser using DataLab