Plot interactive time series of an oceanographic variable

plot_timeseries(
  d,
  fld_date,
  fld_avg,
  fld_sd,
  title = "Temperature",
  y_label = "Temperature (ºC)",
  color = "red"
)

Arguments

d

data frame with data

fld_date

unquoted name of field containing the date, e.g. year

fld_avg

unquoted name of field containing the average value, e.g. t_deg_c_avg

fld_sd

unquoted name of field containing the standard deviation, e.g. sd

title

quoted title, Default is "Temperature".

y_label

quoted label for y-axis. Default is "Temperature (ºC)".

color

quoted color. Should be one of grDevices::colors(). Default is "red".

Value

interactive plot of dygraphs::dygraph()

Examples

# get variables
(v <- get_variables())
#> # A tibble: 3 × 6
#>   category      table_field          plot_title        plot_la…¹ plot_…² color…³
#>   <chr>         <chr>                <chr>             <chr>     <chr>   <chr>  
#> 1 Oceanographic ctd_bottles.t_degc   Temperature       Temperat… red     Reds   
#> 2 Oceanographic ctd_bottles.salinity Salinity          Salinity… purple  Purples
#> 3 Oceanographic ctd_bottles.o2sat    Oxygen Saturation Oxygen p… blue    Blues  
#> # … with abbreviated variable names ¹​plot_label, ²​plot_color, ³​color_palette

# get data for the first variable
(d <- get_timeseries(v$table_field[1]))
#> # A tibble: 71 × 4
#>     year val_avg val_sd n_obs
#>    <dbl>   <dbl>  <dbl> <dbl>
#>  1  1949    9.12   4.68 28081
#>  2  1950    9.12   4.37 38298
#>  3  1951    9.19   4.54 40459
#>  4  1952   10.4    4.03 31690
#>  5  1953   10.6    3.71 29789
#>  6  1954   10.8    4.33 18874
#>  7  1955   10.1    4.71 23248
#>  8  1956   11.2    4.41 14274
#>  9  1957   13.0    5.04 19072
#> 10  1958   12.1    4.71 24324
#> # … with 61 more rows

# plot time series with the first variable
with(v[1,],
  plot_timeseries(
    # data and columns (from d)
    d, year, t_deg_c_avg, t_deg_c_sd,
    # plot attributes (from v)
    plot_title, plot_label, plot_color))
#> Error in dplyr::mutate(., `-sd` = {    {        fld_avg    }} - {    {        fld_sd    }}, `+sd` = {    {        fld_avg    }} + {    {        fld_sd    }}): Problem while computing `-sd = t_deg_c_avg - t_deg_c_sd`.
#> Caused by error:
#> ! object 't_deg_c_avg' not found