Title: | Using ggplot2 in FLR |
---|---|
Description: | Using ggplot2 for FLR. Provides (1) overloaded ggplot methods for various FLR classes, (2) ggplot-based versions of standard plots in the FLCore package, and (3) new geoms for using FLR objects. |
Authors: | Iago Mosqueira [cre, aut] , Laurence T. Kell [aut] |
Maintainer: | Iago Mosqueira <[email protected]> |
License: | GPL-2 |
Version: | 2.7.0.9133 |
Built: | 2024-11-03 04:21:37 UTC |
Source: | https://github.com/flr/ggplotFL |
A correlation plot that show and quantifies correlation along cohorts. Typically used on catch or survey abundances-at-age.
cohcorrplot(x, ...) ## S4 method for signature 'FLQuant' cohcorrplot(x, ...) ## S4 method for signature 'FLCohort' cohcorrplot(x, diag_size = 16, lower_size = 6)
cohcorrplot(x, ...) ## S4 method for signature 'FLQuant' cohcorrplot(x, ...) ## S4 method for signature 'FLCohort' cohcorrplot(x, diag_size = 16, lower_size = 6)
x |
An object with the abundance at age information. FLQuant or FLCohort. |
... |
Any extra arguments |
diag_size |
Font size for labels in diagonal row |
lower_size |
Font size for labels in lower triangle |
The method prints a plot assembled as a combination of grid elements, but reurns it as a gg object.
The FLR Team
data(ple4) cohcorrplot(catch.n(ple4)) cohcorrplot(FLCohort(stock.n(ple4)))
data(ple4) cohcorrplot(catch.n(ple4)) cohcorrplot(FLCohort(stock.n(ple4)))
These functions create labels from FLSR models and params to be used, for example, on the legend of the ggplot-based plot method for FLSRs
eqlabel(model, param) modlabel(model, param)
eqlabel(model, param) modlabel(model, param)
model |
a list of model formulas |
param |
a list of FLPar objects for the params slot |
data(nsher) srs <- FLSRs(sapply(c('ricker', 'bevholt'), function(x) { y <- nsher model(y) <- x return(fmle(y)) })) eqlabel(model=lapply(srs, model), param=lapply(srs, params)) modlabel(model=lapply(srs, model), param=lapply(srs, params))
data(nsher) srs <- FLSRs(sapply(c('ricker', 'bevholt'), function(x) { y <- nsher model(y) <- x return(fmle(y)) })) eqlabel(model=lapply(srs, model), param=lapply(srs, params)) modlabel(model=lapply(srs, model), param=lapply(srs, params))
Plot methods defined in the ggplotFL package make use by default of a palette with a high contrast, useful to separate time series or categories. The palette consist of seven colours: red, blue, green, violet, orange, yellow and brown. This palette can be inspected at the [colorbrewe2.org site](http://colorbrewer2.org/?type=qualitative&scheme=Set1&n=7#type=qualitative&scheme=Set1&n=7).
flpalette flpalette_colours(n = length(flpalette)) flpalette_grads(palette = flpalette, reverse = FALSE, ...) scale_colour_flr(palette = flpalette, discrete = TRUE, reverse = FALSE, ...)
flpalette flpalette_colours(n = length(flpalette)) flpalette_grads(palette = flpalette, reverse = FALSE, ...) scale_colour_flr(palette = flpalette, discrete = TRUE, reverse = FALSE, ...)
n |
Number of colours or individual colours to return, or number of colours to interpolate. |
palette |
Palette subset to create a gradual scale from, defaults to *flpalette*. |
reverse |
Should the palette be reversed, FALSE. |
... |
Elements to subset from palette, by name or position. |
discrete |
Is the palette to be applied to a discrete variable, TRUE. |
An object of class character
of length 8.
The palette is accessible as a named vector, *flpalette*. Two functions are also available to manipualte the palette. One to extract a subset of the palette, *flpalette_colours*, and another to create a gradation of colours between two or more of the palette colours, *flpalette_grads*.
A named vector of colors and HEX codes, or a function to obtain a gradient of colors fo a given length.
The FLR Team
# CHECK flpalette flpalette scales::show_col(flpalette) flpalette_colours() flpalette_colours(5) flpalette_colours(2:3) flpalette_grads(flpalette_colours(3))(20)
# CHECK flpalette flpalette scales::show_col(flpalette) flpalette_colours() flpalette_colours(5) flpalette_colours(2:3) flpalette_grads(flpalette_colours(3))(20)
This 'geom' shows a horizontal line for each 'param' in a 'FLPar' object and labels it using the 'param' dimnames, by calling 'geom_hline' and 'ggrepel::geom_label_repel'. Separate labels and lines can be specified for different facets by providing the 'data' argument with an object of class 'FLPars' in which each element is named as the values of the facetting variable.
geom_flpar(mapping = NULL, data, ..., x, na.rm = FALSE)
geom_flpar(mapping = NULL, data, ..., x, na.rm = FALSE)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
... |
Other arguments passed on to |
x |
Position for params labels on the x axis |
na.rm |
If |
'geom_flpar' understands the following aesthetics (required aesthetics are in bold). Some aesthetics apply to only one of the two elements, in parenthesis: - '*x*' - 'y', defaults to 90 - 'yintercept', defaults to params value (line). - 'label', defaults to params names. - 'alpha' - 'colour' - 'linetype' (line) - 'linewidth' (line) - 'fill' (label) - 'angle' (label) - 'family' (label)
data(ple4) plot(ssb(ple4)) + geom_flpar(data=FLPar(Blim=300000), x=1960) plot(ssb(ple4)) + geom_flpar(data=FLPar(Blim=300000), x=2015) plot(ssb(ple4)) + geom_flpar(data=FLPar(Blim=300000, Bpa=230000), x=1960) # geom works for multiple facets, separate params using name-matching FLPars() plot(ple4, metrics=list(SSB=ssb, F=fbar)) + geom_flpar(data=FLPars(SSB=FLPar(Blim=300000, Bpa=230000), F=FLPar(FMSY=0.21)), x=c(1964)) # x and y positions can be altered by param plot(ple4, metrics=list(SSB=ssb, F=fbar)) + geom_flpar(data=FLPars(SSB=FLPar(Blim=300000, Bpa=230000), F=FLPar(FMSY=0.21)), x=c(2015, 2015, 1960), y=c(340000, 180000, 0.18))
data(ple4) plot(ssb(ple4)) + geom_flpar(data=FLPar(Blim=300000), x=1960) plot(ssb(ple4)) + geom_flpar(data=FLPar(Blim=300000), x=2015) plot(ssb(ple4)) + geom_flpar(data=FLPar(Blim=300000, Bpa=230000), x=1960) # geom works for multiple facets, separate params using name-matching FLPars() plot(ple4, metrics=list(SSB=ssb, F=fbar)) + geom_flpar(data=FLPars(SSB=FLPar(Blim=300000, Bpa=230000), F=FLPar(FMSY=0.21)), x=c(1964)) # x and y positions can be altered by param plot(ple4, metrics=list(SSB=ssb, F=fbar)) + geom_flpar(data=FLPars(SSB=FLPar(Blim=300000, Bpa=230000), F=FLPar(FMSY=0.21)), x=c(2015, 2015, 1960), y=c(340000, 180000, 0.18))
This 'geom' calculates sampling quantiles and draws a ribbon for the quantile range plus a line for the median (50% quantile).
geom_flquantiles( mapping = NULL, data = NULL, stat = "FLQuantiles", position = "identity", show.legend = NA, inherit.aes = TRUE, na.rm = FALSE, probs = c(0.1, 0.5, 0.9), alpha = 0.5, ... ) stat_flquantiles( mapping = NULL, data = NULL, geom = "line", position = "identity", na.rm = TRUE, show.legend = NA, inherit.aes = TRUE, ... )
geom_flquantiles( mapping = NULL, data = NULL, stat = "FLQuantiles", position = "identity", show.legend = NA, inherit.aes = TRUE, na.rm = FALSE, probs = c(0.1, 0.5, 0.9), alpha = 0.5, ... ) stat_flquantiles( mapping = NULL, data = NULL, geom = "line", position = "identity", na.rm = TRUE, show.legend = NA, inherit.aes = TRUE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this
layer, either as a |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
na.rm |
If |
probs |
Quantiles to compute and draw, defaults to c(0.10, 0.90). |
alpha |
Transparency for quantile ribbon. |
... |
Other arguments passed on to |
geom |
The geometric object to use to display the data, either as a
|
As this 'geom' outputs two layers, although based on different 'geoms', interactions between common parameters need to be considered. The 'fill' parameter will only affect the quantile range 'ribbon', but 'colour' will be passed to both the 'ribbon' and median 'line' layers. The defaults are no lines on the quantiles and "black" for the median line. The 'alpha' value has been hard coded to 1 for the median line, so only affects the quantile 'ribbon'. To change this, call 'stat_flquantiles' directly, as in the examples below.
'stat_flquantiles' will return between one and three 'y' values depending on the number of quantiles requested. If two quantiles are to be calculated, it will return the corresponding 'ymin' and 'ymax', to be used with, for example, 'geom_ribbon'. If only one quantile is to be calculated, it will be returned as 'y', to be used typically by 'geom_line'. Finally, if three values are passed in the 'probs' argument, all of the above will be returned, in the right order.
'geom_flquantiles' understands the following aesthetics (required aesthetics are in bold): - '*x*' - '*y*' - 'alpha' - 'colour' - 'fill' - 'group' - 'linetype' - 'linewidth' where some of them apply to the ribbons and some of them to the lines.
quantile, if only one requested or central one when if three
lower quantile, if two or three requested
upper quantile, if two or three requested
data(ple4) flq <- rnorm(250, catch(ple4), 200000) ggplot(flq, aes(x=date, y=data)) + geom_flquantiles(probs=c(0.25, 0.50, 0.75), fill="red", alpha=0.25) # Draw two quantiles with two calls to geom_flquantiles ggplot(flq, aes(x=date, y=data)) + geom_flquantiles(probs=c(0.25, 0.50, 0.75), alpha=0.25, fill="red") + geom_flquantiles(probs=c(0.10, 0.90), alpha=0.15, fill="red") # Use it on an FLQuants, colouring by their name flqs <- FLQuants(A=rnorm(250, catch(ple4), 200000), B=rnorm(250, stock(ple4), 200000)) ggplot(flqs, aes(x=date, y=data, colour=qname)) + geom_flquantiles(probs=c(0.10, 0.50, 0.90), aes(fill=qname), alpha=c(0.30)) # Or facet them ggplot(flqs, aes(x=date, y=data)) + geom_flquantiles(probs=c(0.10, 0.50, 0.90), fill="red", alpha=c(0.30)) + facet_grid(qname~.) # For greater control, call stat_flquantiles directly with a geom ggplot(flq, aes(x=year, y=data)) + stat_flquantiles(probs=c(0.10, 0.90), geom = "ribbon", fill="yellowgreen", alpha=0.30) + stat_flquantiles(probs=c(0.01), geom = "line", colour = "green4", linetype=3) + stat_flquantiles(probs=c(0.99), geom = "line", colour = "green4", linetype=3) + stat_flquantiles(probs=c(0.25, 0.75), geom = "ribbon", fill="green4", alpha=0.30) + stat_flquantiles(probs=c(0.50), geom = "line", linewidth=1.5, colour = "lightgreen") + stat_flquantiles(probs=c(0.50), geom = "line", colour = "darkgreen")
data(ple4) flq <- rnorm(250, catch(ple4), 200000) ggplot(flq, aes(x=date, y=data)) + geom_flquantiles(probs=c(0.25, 0.50, 0.75), fill="red", alpha=0.25) # Draw two quantiles with two calls to geom_flquantiles ggplot(flq, aes(x=date, y=data)) + geom_flquantiles(probs=c(0.25, 0.50, 0.75), alpha=0.25, fill="red") + geom_flquantiles(probs=c(0.10, 0.90), alpha=0.15, fill="red") # Use it on an FLQuants, colouring by their name flqs <- FLQuants(A=rnorm(250, catch(ple4), 200000), B=rnorm(250, stock(ple4), 200000)) ggplot(flqs, aes(x=date, y=data, colour=qname)) + geom_flquantiles(probs=c(0.10, 0.50, 0.90), aes(fill=qname), alpha=c(0.30)) # Or facet them ggplot(flqs, aes(x=date, y=data)) + geom_flquantiles(probs=c(0.10, 0.50, 0.90), fill="red", alpha=c(0.30)) + facet_grid(qname~.) # For greater control, call stat_flquantiles directly with a geom ggplot(flq, aes(x=year, y=data)) + stat_flquantiles(probs=c(0.10, 0.90), geom = "ribbon", fill="yellowgreen", alpha=0.30) + stat_flquantiles(probs=c(0.01), geom = "line", colour = "green4", linetype=3) + stat_flquantiles(probs=c(0.99), geom = "line", colour = "green4", linetype=3) + stat_flquantiles(probs=c(0.25, 0.75), geom = "ribbon", fill="green4", alpha=0.30) + stat_flquantiles(probs=c(0.50), geom = "line", linewidth=1.5, colour = "lightgreen") + stat_flquantiles(probs=c(0.50), geom = "line", colour = "darkgreen")
A geom for adding worms to probability intervals from geom_flquantiles
geom_worm( data, mapping = aes(colour = iter), ..., stat = "identity", position = "identity", na.rm = FALSE )
geom_worm( data, mapping = aes(colour = iter), ..., stat = "identity", position = "identity", na.rm = FALSE )
data |
Subset of data, select from full object using iter(). |
mapping |
Set of aesthetic mappings created by |
... |
Other arguments passed on to |
stat |
The statistical transformation to use on the data for this
layer, either as a |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
na.rm |
If |
'geom_worm' understands the following aesthetics (required aesthetics are in bold): - 'colour' - 'linetype' - 'linewidth'
data(ple4) x <- rlnorm(200, log(catch(ple4)), 0.3) plot(x) + geom_worm(data=iter(x, 1:4)) x <- FLQuants(C=rlnorm(200, log(catch(ple4)), 0.3), F=rlnorm(200, fbar(ple4), 0.2)) plot(x) + geom_worm(data=iter(x, 1:4))
data(ple4) x <- rlnorm(200, log(catch(ple4)), 0.3) plot(x) + geom_worm(data=iter(x, 1:4)) x <- FLQuants(C=rlnorm(200, log(catch(ple4)), 0.3), F=rlnorm(200, fbar(ple4), 0.2)) plot(x) + geom_worm(data=iter(x, 1:4))
The ggplot()
method has been conveniently overloaded for various
FLR classes. A call to as.data.frame
takes place on data
before passing all arguments to the original ggplot
function.
## S4 method for signature 'FLQuant' ggplot(data = NULL, mapping = aes(), ..., environment = parent.frame()) ## S4 method for signature 'FLQuants' ggplot(data = NULL, mapping = aes(), ..., environment = parent.frame()) ## S4 method for signature 'FLComp' ggplot(data = NULL, mapping = aes(), ..., environment = parent.frame()) ## S4 method for signature 'FLComps' ggplot(data = NULL, mapping = aes(), ..., environment = parent.frame()) ## S4 method for signature 'FLPar' ggplot(data = NULL, mapping = aes(), ..., environment = parent.frame())
## S4 method for signature 'FLQuant' ggplot(data = NULL, mapping = aes(), ..., environment = parent.frame()) ## S4 method for signature 'FLQuants' ggplot(data = NULL, mapping = aes(), ..., environment = parent.frame()) ## S4 method for signature 'FLComp' ggplot(data = NULL, mapping = aes(), ..., environment = parent.frame()) ## S4 method for signature 'FLComps' ggplot(data = NULL, mapping = aes(), ..., environment = parent.frame()) ## S4 method for signature 'FLPar' ggplot(data = NULL, mapping = aes(), ..., environment = parent.frame())
data |
An |
mapping |
An aesthetic mapping, from a call to |
... |
Other arguments to be passod on to |
environment |
Where to look for an undefined plot variable. |
Please look at the relevant as.data.frame
method for each class to
understand the naming conventions used in the resulting data.frame
ggplot, https://github.com/flr/ggplotFL/
dat <- rnorm(1, FLQuant(1, dim=c(5,10)), 0.5) ggplot(data=dat, aes(data, year)) + geom_point() data(ple4) dat <- FLQuants(catch=catch(ple4), ssb=ssb(ple4)) ggplot(data=dat, aes(data, year)) + geom_point() + facet_wrap(~qname)
dat <- rnorm(1, FLQuant(1, dim=c(5,10)), 0.5) ggplot(data=dat, aes(data, year)) + geom_point() data(ple4) dat <- FLQuants(catch=catch(ple4), ssb=ssb(ple4)) ggplot(data=dat, aes(data, year)) + geom_point() + facet_wrap(~qname)
This function formats numbers for output in a 'human' way.
human_numbers(x = NULL, smbl = "", signif = 1)
human_numbers(x = NULL, smbl = "", signif = 1)
x |
An object of class |
smbl |
A character or symbol to be added prior to the number, e.g. an euro sign. |
signif |
Number of significant figures |
A formatted character vector
Iago Mosqueira (EC JRC)
This function provides sensible breaks for integers
integer_breaks(n = 5, ...)
integer_breaks(n = 5, ...)
n |
Number of breaks |
... |
Arguments to be passed to *pretty* |
A function to be called
Iago Mosqueira (WMR)
Plots of FLQuants
objects use by default facet_grid
to separate the different elements. This function generates facet labels that
have both the element name and the units of measurement of each, as stored
in the 'units' slot of each FLQuant
.
label_flqs(x, drop = c("NA", "NC", "m", "f", "z", "prop"))
label_flqs(x, drop = c("NA", "NC", "m", "f", "z", "prop"))
x |
An object of class |
drop |
Character string to be dropped from the label shen found in the *units* slot. Defaults to c("NA", "NC", "m", "z", "prop") |
Certain *units* are dropped from the label, as being uninformative: "NA", "NC", "m", "z", and "prop". This can be selected with the *drop* argument.
A ggplot2 labeller function
Iago Mosqueira (EC JRC)
New basic plot methods for some FLR classes are defined in ggplotFL.
## S4 method for signature 'FLQuant,missing' plot(x, probs = c(0.05, 0.25, 0.5, 0.75, 0.95), na.rm = FALSE, ...) ## S4 method for signature 'FLQuant,FLQuant' plot( x, y, ..., probs = c(0.05, 0.25, 0.5, 0.75, 0.95), na.rm = FALSE, iter = NULL ) ## S4 method for signature 'FLQuants,missing' plot( x, probs = c(0.05, 0.25, 0.5, 0.75, 0.95), na.rm = FALSE, worm = iter, iter = NULL ) ## S4 method for signature 'FLQuants,FLPar' plot(x, y, ...) ## S4 method for signature 'FLQuants,FLPars' plot(x, y, ...) ## S4 method for signature 'FLQuantPoint,missing' plot(x, mean = TRUE, median = TRUE) ## S4 method for signature 'FLQuantPoint,FLQuant' plot(x, y, na.rm = FALSE, ...) ## S4 method for signature 'FLQuantPoint,FLQuants' plot(x, y, na.rm = FALSE, mean = TRUE, median = TRUE, ...) ## S4 method for signature 'FLPar,missing' plot(x, names = NULL) ## S4 method for signature 'FLStock,missing' plot( x, metrics = list(Rec = rec, SSB = ssb, Catch = catch, F = fbar), na.rm = TRUE, ... ) ## S4 method for signature 'FLStock,FLStock' plot( x, y, metrics = list(Rec = rec, SSB = ssb, Catch = catch, F = fbar), probs = c(0.1, 0.33, 0.5, 0.66, 0.9), na.rm = TRUE, iter = NULL, ... ) ## S4 method for signature 'FLStock,FLPar' plot(x, y, metrics = list(Rec = rec, SSB = ssb, Catch = catch, F = fbar), ...) ## S4 method for signature 'FLStocks,missing' plot( x, metrics = list(Rec = function(x) unitSums(rec(x)), SB = function(x) unitSums(ssb(x)), C = function(x) unitSums(catch(x)), F = function(x) unitMeans(fbar(x))), probs = c(0.1, 0.33, 0.5, 0.66, 0.9), alpha = c(0.1, 0.4), worm = iter, iter = NULL, ... ) ## S4 method for signature 'FLStocks,missing' plot( x, metrics = list(Rec = function(x) unitSums(rec(x)), SB = function(x) unitSums(ssb(x)), C = function(x) unitSums(catch(x)), F = function(x) unitMeans(fbar(x))), probs = c(0.1, 0.33, 0.5, 0.66, 0.9), alpha = c(0.1, 0.4), worm = iter, iter = NULL, ... ) ## S4 method for signature 'FLStocks,FLPar' plot( x, y, na.rm = TRUE, metrics = function(x, y) FLQuants(SSB = ssb(x)/y[, "ssb", ], F = fbar(x)/y[, "harvest", ], Catch = catch(x)) ) ## S4 method for signature 'FLStock,FLStocks' plot(x, y, ...) ## S4 method for signature 'FLSR,missing' plot(x, y, ...) ## S4 method for signature 'FLSRs,ANY' plot(x, legend_label = names(x), facets = FALSE, ...) ## S4 method for signature 'FLBiol,missing' plot(x, metrics = list(Rec = function(x) n(x)[1, ], B = tsb), ...) ## S4 method for signature 'FLBiols,missing' plot(x, metrics = list(Rec = function(x) n(x)[1, ], B = tsb), ...) ## S4 method for signature 'FLIndexBiomass,missing' plot(x, y, ...) ## S4 method for signature 'FLIndex,missing' plot(x) ## S4 method for signature 'FLIndices,missing' plot(x)
## S4 method for signature 'FLQuant,missing' plot(x, probs = c(0.05, 0.25, 0.5, 0.75, 0.95), na.rm = FALSE, ...) ## S4 method for signature 'FLQuant,FLQuant' plot( x, y, ..., probs = c(0.05, 0.25, 0.5, 0.75, 0.95), na.rm = FALSE, iter = NULL ) ## S4 method for signature 'FLQuants,missing' plot( x, probs = c(0.05, 0.25, 0.5, 0.75, 0.95), na.rm = FALSE, worm = iter, iter = NULL ) ## S4 method for signature 'FLQuants,FLPar' plot(x, y, ...) ## S4 method for signature 'FLQuants,FLPars' plot(x, y, ...) ## S4 method for signature 'FLQuantPoint,missing' plot(x, mean = TRUE, median = TRUE) ## S4 method for signature 'FLQuantPoint,FLQuant' plot(x, y, na.rm = FALSE, ...) ## S4 method for signature 'FLQuantPoint,FLQuants' plot(x, y, na.rm = FALSE, mean = TRUE, median = TRUE, ...) ## S4 method for signature 'FLPar,missing' plot(x, names = NULL) ## S4 method for signature 'FLStock,missing' plot( x, metrics = list(Rec = rec, SSB = ssb, Catch = catch, F = fbar), na.rm = TRUE, ... ) ## S4 method for signature 'FLStock,FLStock' plot( x, y, metrics = list(Rec = rec, SSB = ssb, Catch = catch, F = fbar), probs = c(0.1, 0.33, 0.5, 0.66, 0.9), na.rm = TRUE, iter = NULL, ... ) ## S4 method for signature 'FLStock,FLPar' plot(x, y, metrics = list(Rec = rec, SSB = ssb, Catch = catch, F = fbar), ...) ## S4 method for signature 'FLStocks,missing' plot( x, metrics = list(Rec = function(x) unitSums(rec(x)), SB = function(x) unitSums(ssb(x)), C = function(x) unitSums(catch(x)), F = function(x) unitMeans(fbar(x))), probs = c(0.1, 0.33, 0.5, 0.66, 0.9), alpha = c(0.1, 0.4), worm = iter, iter = NULL, ... ) ## S4 method for signature 'FLStocks,missing' plot( x, metrics = list(Rec = function(x) unitSums(rec(x)), SB = function(x) unitSums(ssb(x)), C = function(x) unitSums(catch(x)), F = function(x) unitMeans(fbar(x))), probs = c(0.1, 0.33, 0.5, 0.66, 0.9), alpha = c(0.1, 0.4), worm = iter, iter = NULL, ... ) ## S4 method for signature 'FLStocks,FLPar' plot( x, y, na.rm = TRUE, metrics = function(x, y) FLQuants(SSB = ssb(x)/y[, "ssb", ], F = fbar(x)/y[, "harvest", ], Catch = catch(x)) ) ## S4 method for signature 'FLStock,FLStocks' plot(x, y, ...) ## S4 method for signature 'FLSR,missing' plot(x, y, ...) ## S4 method for signature 'FLSRs,ANY' plot(x, legend_label = names(x), facets = FALSE, ...) ## S4 method for signature 'FLBiol,missing' plot(x, metrics = list(Rec = function(x) n(x)[1, ], B = tsb), ...) ## S4 method for signature 'FLBiols,missing' plot(x, metrics = list(Rec = function(x) n(x)[1, ], B = tsb), ...) ## S4 method for signature 'FLIndexBiomass,missing' plot(x, y, ...) ## S4 method for signature 'FLIndex,missing' plot(x) ## S4 method for signature 'FLIndices,missing' plot(x)
x |
FLR object to plot |
probs |
Quantiles to calculate along the iter dimension. A vector of length 5, for the lower outer, lower inner, central, upper inner and upper outer quantiles. Defaults to the 66 and 80 percent quantiles, plus median line. |
na.rm |
Should NAs be deleted in quantile calculations?, defaults to TRUE. |
... |
Other arguments to be passed to the corresponding ggplot call. |
y |
FLR object to plot |
iter |
Individual iterations to show as worm plots over the quantiles. |
worm |
Individual iterations to show as worm plots over the quantiles. |
metrics |
function returning an FLQuants for each FLStock |
alpha |
alpha values for the quantile ribbons, defaults to 0.10 and 0.40. |
legend_label |
function to create the legend labels |
The coertion to *data.frame* that is carried out in the plot methods sets the argument 'date=TRUE'. This generates a new column of class 'POSIXct' for the first day of the first month of each season. If the 'season' dimension of the object being plotted is of length greater than one, 'date' will be used as variable on the x axis of the plot. Otherwise, it will be 'year'. Keep this in mind when adding extra elements to the plot (see examples below).
A similar mechanism is used for the *y* axis, depending on the length of the 'iter' dimension. For objects with no *iters*, a single line is plotted for each *FLQuant*, and the *y* axis is mapped to the 'data' column of the *data.frame*. For objects with iterations, i.e. with length greater than 1 on the 'iter' dimension, the default plots show the quantiles of the distribution and the *y* axis is mapped to the middle quantile, by default '50 examples below on how to refer to these variables when adding elements to the plot.
# Plot a single FLQuant data(ple4) plot(catch.n(ple4)) # Plot an FLQuant with iters, shows quantiles flq <- rnorm(100, catch(ple4), 60000) plot(flq) # Specify quantiles, default is c(0.10, 0.33, 0.50, 0.66, 0.90) plot(flq, probs=c(0.05, 0.25, 0.50, 0.75, 0.95)) # Adding extra elements to an FLQuant plot, with seasons flq <- FLQuant(runif(200), dim=c(1,15,1,4)) plot(flq) + geom_point(aes(x=date, y=data, colour=season)) # or without them flq <- FLQuant(runif(200), dim=c(1,15)) plot(flq) + geom_point(aes(x=year, y=data)) # For an object with iter flq <- rlnorm(100, flq, 0.4) plot(flq) + geom_point(aes(x=year, y=data)) # To plot(FLQuant) as in previous versions of ggplotFL plot(rnorm(300, catch(ple4), catch(ple4)/2), probs=c(0.10, 0.5, 0.90)) + geom_flquantiles(probs=c(0.01), linetype=3, colour="red", alpha=0.1) + geom_flquantiles(probs=c(0.99), linetype=3, colour="red", alpha=0.1) # plot(FLQuant, FLQuant, ...) to place in one facet plot(catch(ple4), landings(ple4)) # Add legend by hand plot(rnorm(200, landings(ple4), 8000), discards(ple4)) + scale_colour_discrete(name="Yield (t)", labels=c("Landings", "Discards")) + theme(legend.position="bottom") # Plot an FLQuants created from ple4 FLStock data(ple4) plot(FLQuants(SSB=ssb(ple4), rec=rec(ple4))) plot(FLQuants(SSB=ssb(ple4), rec=rec(ple4)), probs = NULL) # plot for FLQuants, FLPar data(ple4) rps <- FLPar(F=0.14, Catch=1.29e5, Rec=9.38e5, SSB=1.8e5) fqs <- metrics(ple4) plot(fqs, rps) # Works also if reptsa are given for some panels rps <- FLPar(F=0.14, Catch=1.29e5, SSB=1.8e5) plot(fqs, rps) # plot for FLQuants, FLPars data(ple4) rps <- FLPars(F=FLPar(Fmsy=0.14, Fpa=0.35), SSB=FLPar(SBmsy=1.8e5, SBlim=1.1e5)) fqs <- metrics(ple4, list(SSB=ssb, F=fbar)) plot(fqs, rps) + ylim(c(0, NA)) # plot for FLQuantPoint fqp <- FLQuantPoint(rlnorm(300, log(catch(ple4)), 0.20)) plot(fqp) # plot for FLQuantPoint, FLQuant plot(fqp, rlnorm(3, log(catch(ple4)), 0.20)) # plot for FLQuantPoint, FLQuants fqp <- FLQuantPoint(rlnorm(300, log(catch(ple4)), 0.20)) fqs <- divide(rlnorm(3, log(catch(ple4)), 0.20)) plot(fqp, fqs) par <- FLPar(alpha=rnorm(200, 0.6, 0.2), beta=rlnorm(200, 0.8, 0.3)) plot(par) # plot of an FLStock data(ple4) plot(ple4) # plot for FLStock, FLPar data(ple4) rps <- FLPar(F=0.14, Catch=1.29e5, Rec=9.38e5, SSB=1.8e5) plot(ple4, rps) # plot for FLStocks data(ple4) pls <- FLStocks(runA=ple4, runB=qapply(ple4, function(x) x*1.10)) plot(pls) # geom_flpar can be used draw refpts lines and labels plot(pls, metrics=list(SSB=ssb, F=fbar)) + facet_grid(qname~stock, scales='free') + geom_flpar(data=FLPars(SSB=FLPar(Blim=300000, Bpa=230000), F=FLPar(FMSY=0.21)), x=c(1960), stock='runA', fill=alpha('white', 0.4)) # plot for FLStocks data(ple4) pls <- FLStocks(runA=ple4, runB=qapply(ple4, function(x) x*1.10)) plot(pls) # geom_flpar can then be used draw refpts lines and labels plot(pls, metrics=list(SSB=ssb, F=fbar)) + facet_grid(qname~stock, scales='free') + geom_flpar(data=FLPars(SSB=FLPar(Blim=300000, Bpa=230000), F=FLPar(FMSY=0.21)), x=c(1960), stock='runA', fill=alpha('white', 0.4)) # plot for FLSR data(nsher) plot(nsher) # plot for FLSRs data(nsher) srs <- FLSRs(sapply(c('segreg', 'bevholt'), function(x) { y <- nsher model(y) <- x return(fmle(y)) })) plot(srs, facets=TRUE) plot(srs, legend_label=eqlabel) plot(srs, legend_label=modlabel) # Plot a FLIndex object data(ple4.index) plot(ple4.index) # Plot a FLIndices object data(ple4.indices) plot(ple4.indices) plot(ple4.indices) + geom_smooth(formula=y ~ x, se=FALSE, method="loess", linewidth=0.2)
# Plot a single FLQuant data(ple4) plot(catch.n(ple4)) # Plot an FLQuant with iters, shows quantiles flq <- rnorm(100, catch(ple4), 60000) plot(flq) # Specify quantiles, default is c(0.10, 0.33, 0.50, 0.66, 0.90) plot(flq, probs=c(0.05, 0.25, 0.50, 0.75, 0.95)) # Adding extra elements to an FLQuant plot, with seasons flq <- FLQuant(runif(200), dim=c(1,15,1,4)) plot(flq) + geom_point(aes(x=date, y=data, colour=season)) # or without them flq <- FLQuant(runif(200), dim=c(1,15)) plot(flq) + geom_point(aes(x=year, y=data)) # For an object with iter flq <- rlnorm(100, flq, 0.4) plot(flq) + geom_point(aes(x=year, y=data)) # To plot(FLQuant) as in previous versions of ggplotFL plot(rnorm(300, catch(ple4), catch(ple4)/2), probs=c(0.10, 0.5, 0.90)) + geom_flquantiles(probs=c(0.01), linetype=3, colour="red", alpha=0.1) + geom_flquantiles(probs=c(0.99), linetype=3, colour="red", alpha=0.1) # plot(FLQuant, FLQuant, ...) to place in one facet plot(catch(ple4), landings(ple4)) # Add legend by hand plot(rnorm(200, landings(ple4), 8000), discards(ple4)) + scale_colour_discrete(name="Yield (t)", labels=c("Landings", "Discards")) + theme(legend.position="bottom") # Plot an FLQuants created from ple4 FLStock data(ple4) plot(FLQuants(SSB=ssb(ple4), rec=rec(ple4))) plot(FLQuants(SSB=ssb(ple4), rec=rec(ple4)), probs = NULL) # plot for FLQuants, FLPar data(ple4) rps <- FLPar(F=0.14, Catch=1.29e5, Rec=9.38e5, SSB=1.8e5) fqs <- metrics(ple4) plot(fqs, rps) # Works also if reptsa are given for some panels rps <- FLPar(F=0.14, Catch=1.29e5, SSB=1.8e5) plot(fqs, rps) # plot for FLQuants, FLPars data(ple4) rps <- FLPars(F=FLPar(Fmsy=0.14, Fpa=0.35), SSB=FLPar(SBmsy=1.8e5, SBlim=1.1e5)) fqs <- metrics(ple4, list(SSB=ssb, F=fbar)) plot(fqs, rps) + ylim(c(0, NA)) # plot for FLQuantPoint fqp <- FLQuantPoint(rlnorm(300, log(catch(ple4)), 0.20)) plot(fqp) # plot for FLQuantPoint, FLQuant plot(fqp, rlnorm(3, log(catch(ple4)), 0.20)) # plot for FLQuantPoint, FLQuants fqp <- FLQuantPoint(rlnorm(300, log(catch(ple4)), 0.20)) fqs <- divide(rlnorm(3, log(catch(ple4)), 0.20)) plot(fqp, fqs) par <- FLPar(alpha=rnorm(200, 0.6, 0.2), beta=rlnorm(200, 0.8, 0.3)) plot(par) # plot of an FLStock data(ple4) plot(ple4) # plot for FLStock, FLPar data(ple4) rps <- FLPar(F=0.14, Catch=1.29e5, Rec=9.38e5, SSB=1.8e5) plot(ple4, rps) # plot for FLStocks data(ple4) pls <- FLStocks(runA=ple4, runB=qapply(ple4, function(x) x*1.10)) plot(pls) # geom_flpar can be used draw refpts lines and labels plot(pls, metrics=list(SSB=ssb, F=fbar)) + facet_grid(qname~stock, scales='free') + geom_flpar(data=FLPars(SSB=FLPar(Blim=300000, Bpa=230000), F=FLPar(FMSY=0.21)), x=c(1960), stock='runA', fill=alpha('white', 0.4)) # plot for FLStocks data(ple4) pls <- FLStocks(runA=ple4, runB=qapply(ple4, function(x) x*1.10)) plot(pls) # geom_flpar can then be used draw refpts lines and labels plot(pls, metrics=list(SSB=ssb, F=fbar)) + facet_grid(qname~stock, scales='free') + geom_flpar(data=FLPars(SSB=FLPar(Blim=300000, Bpa=230000), F=FLPar(FMSY=0.21)), x=c(1960), stock='runA', fill=alpha('white', 0.4)) # plot for FLSR data(nsher) plot(nsher) # plot for FLSRs data(nsher) srs <- FLSRs(sapply(c('segreg', 'bevholt'), function(x) { y <- nsher model(y) <- x return(fmle(y)) })) plot(srs, facets=TRUE) plot(srs, legend_label=eqlabel) plot(srs, legend_label=modlabel) # Plot a FLIndex object data(ple4.index) plot(ple4.index) # Plot a FLIndices object data(ple4.indices) plot(ple4.indices) plot(ple4.indices) + geom_smooth(formula=y ~ x, se=FALSE, method="loess", linewidth=0.2)
Plot the runs test result for one or more time series
plotRunstest(fit, obs, ...) ## S4 method for signature 'FLQuants,missing' plotRunstest(fit, combine = TRUE) ## S4 method for signature 'FLQuants,FLQuants' plotRunstest(fit, obs, combine = TRUE) ## S4 method for signature 'FLQuant,FLQuant' plotRunstest(fit, obs, combine = TRUE)
plotRunstest(fit, obs, ...) ## S4 method for signature 'FLQuants,missing' plotRunstest(fit, combine = TRUE) ## S4 method for signature 'FLQuants,FLQuants' plotRunstest(fit, obs, combine = TRUE) ## S4 method for signature 'FLQuant,FLQuant' plotRunstest(fit, obs, combine = TRUE)
fit |
The result of a model fit. |
obs |
The observations used in the fit. |
... |
Extra arguments. |
combine |
Should ages be combined by addition, defaults to TRUE. |
An object of class ggplot2::gg
data(nsher) plotRunstest(fitted(nsher), rec(nsher))
data(nsher) plotRunstest(fitted(nsher), rec(nsher))
Plot of FLIndices cross-validation by retrospective hindcast
plotXval(x, y = "missing", order = "inverse")
plotXval(x, y = "missing", order = "inverse")
x |
An *FLIndices* object of the original observations. |
y |
A list contaning *FLIndices* objects returned by *a4ahcxval*. |
order |
Order in which retrospective runs are stored, defaults to"inverse". |
A ggplot object
# SEE vignette
# SEE vignette
Output ggplot object to PNG files with good quality settings.
pubpng(file, plot, width = 1600, height = 1400, res = 200)
pubpng(file, plot, width = 1600, height = 1400, res = 200)
file |
Output file path and name. |
plot |
ggplot object or command. |
width |
Width of plot, in pixels. Defaults to 1600. |
height |
Height of plot, in pixels. Defaults to 1400. |
res |
Resolution, in ppi. Deagults to 200. |
TRUE if succesful, while file is saved to disk.
grDevices::png
Discrete and continuous versions of the standard ggplotFL palette. See flpalette fo further details.
scale_fill_flr(palette = flpalette, discrete = TRUE, reverse = FALSE, ...)
scale_fill_flr(palette = flpalette, discrete = TRUE, reverse = FALSE, ...)
palette |
Palette subset to create a gradual scale from, defaults to *flpalette*. |
discrete |
Is the palette to be applied to a discrete variable, TRUE. |
reverse |
Should the palette be reversed, FALSE. |
... |
Other arguments to be passed to the scale functions |
A function.
The FLR Team