View source: R/plot-pacea-index.R
plot.pacea_index | R Documentation |
Temporal plot for a pacea index ('pacea_index') object, with options for display style, and adding in times of other events (to ask questions such as 'does this rare event coincide with El Niño?'). See examples and vignette.
## S3 method for class 'pacea_index'
plot(
obj,
value = "anomaly",
xlab = "Date",
ylab = attr(obj, "axis_name"),
smooth_over_year = FALSE,
type = "l",
style = "red_blue_bar",
y_tick_by = 0.25,
y_tick_start = NULL,
y_tick_end = NULL,
y_tick_max_number = 50,
x_tick_extra_years = 200,
start_decade_ticks = lubridate::ymd("1800-01-01", truncated = 2),
event_years = NULL,
event_lub = NULL,
event_pch = 20,
event_cex = 3,
event_col = "grey",
...
)
obj |
a 'pacea_index' object, which is a time series. |
value |
which column of 'obj' to plot |
xlab |
x-axis label |
ylab |
y-axis label, the default is an attribute of the 'pacea_index' object. |
smooth_over_year |
logical to smooth monthly values over each calendar year (as per Tetjana Ross' plots, see '?oni' for reference). Note that the corresponding 'date' is for 1st January of each year. |
type |
usual argument for 'plot()' |
style |
what style of plot:
|
y_tick_by |
increment for y-axis ticks; gets overwritten in 'add_tickmarks()' if this yields more than 'y_tick_max_number' tickmarks. If using [plot.pacea_biomass()] the default of 1 gets automatically changed to 0.25 for 'plot(hake_biomass)'. |
y_tick_start |
where to start y-axis tickmarks, set automatically if not specified (may need to occasionally specify) |
y_tick_end |
where to end y-axis tickmars, as for 'y_tick_start' |
y_tick_max_number |
maximum number of y tickmarks. |
x_tick_extra_years |
number of extra years to expand around the range of data for which to add annual tick marks (does not expand the axis); in hindsight could have simplified this in 'add_tickmarks()', but just made the default big here. |
start_decade_ticks |
where to start tickmarks for decades (defaults to 1800 as hard to automate) |
event_years |
years of the event occurring (e.g. sighting of a rare shark) to add to the plot (sensible for rare-ish events, to quickly see if they coincide with the values of the index); points will be shown for 1st July (Oh Canada!) of the given year, and at the value of the index to make it easy to quickly spot any correlation. Assumes 'event_years' values are unique. For more control instead use 'event_lub'. |
event_lub |
dates of events as lubridate objects (only 'event_years' or 'event_lub' can be specified). Assumes 'event_lub' values are unique. |
event_pch |
'pch' for events |
event_cex |
'cex' for events |
event_col |
'col' for events |
... |
optional arguments passed onto 'plot()'. Note that the x-axis is constructed using a lubridate 'date' object, so 'xlim' needs to be a 'date' object (see example). |
plot of the time series to the current device (returns nothing)
Andrew Edwards
## Not run:
plot(oni)
plot(oni,
xlim = c(lubridate::dmy(01011950),
lubridate::dmy(01012040))) # to expand x-axis
plot(npi_monthly,
value = "value")
# The overlaying of events idea was inspired from a lunchtime conversation regarding a
# rare sighting of a Bluntnose Sixgill Shark by divers in Port Alberni, that garnered
# [media attention](https://www.timescolonist.com/local-news/divers-encounter-deep-water-shark-in-alberni-inlet-7102038).
# A lunchtime conversation with Maxime Veilleux led to the question of whether catches
# f these sharks in BC waters are related to El Niño. Specifically, as the data from
# the International Pacific Halibut Commission annual longline survey are
# readily available in the [gfiphc](https://github.com/pbs-assess/gfiphc)
# package, we looked at years which caught a Bluntnose Sixgill Shark (at a
# standard station, outside of the Strait of Georgia).
library(gfiphc)
sp_set_counts <- iphc_get_calc_plot_full("bluntnose sixgill shark") # Need
access to DFO Groundfish database
bluntnose_caught_years <- unique(filter(sp_set_counts$set_counts, N_it > 0, standard == "Y")$year)
plot(oni,
event_years = bluntnose_caught_years,
xlim = c(lubridate::dmy(01011995), lubridate::dmy(01012024)),
lwd = 2)
# This is not meant to be a definitive analysis, but a demonstration of the plotting options in pacea.
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.