inst/skills/analyse-and-plot/quick-reference.md

# ── Accessing raw arrays ───────────────────────────────────────────────────────
N(sim)                  # time × species × size
NResource(sim)          # time × size
finalN(sim)             # species × size  (last time step)
finalNResource(sim)     # size            (last time step)

# ── Species biomass / abundance / yield (time × species) ──────────────────────
getBiomass(sim)         # total biomass
getSSB(sim)             # spawning stock biomass
getN(sim)               # total abundance (numbers)
getYield(sim)           # catch in weight
getYieldGear(sim)       # catch by gear (time × gear × species)

# ── Rates at size (time × species × size) ─────────────────────────────────────
getFeedingLevel(sim)    # satiation (0 = starving, 1 = full)
getPredMort(sim)        # predation mortality
getFMort(sim)           # fishing mortality
getFMortGear(sim)       # fishing mortality by gear (time × gear × species × size)

# ── Diet and trophic (species × size × …) ────────────────────────────────────
getDiet(params)                  # proportion of diet from each prey
getTrophicLevel(params)          # trophic level at size (species × size)
getTrophicLevelBySpecies(params) # mean trophic level (species)

# ── Community indicators (time series) ────────────────────────────────────────
getProportionOfLargeFish(sim, threshold_w = 100)
getMeanWeight(sim)
getMeanLength(sim)               # needs species_params `a` and `b`
getMeanMaxWeight(sim)
getCommunitySlope(sim)          # returns data.frame with slope, intercept, R²

# ── Your own indicator: an integral over the size spectrum ────────────────────
sizeIntegral(params, weighting = w(params), min_w = 10, max_w = 5000)  # = getBiomass()
sizeIntegral(sim, weighting = sweep(maturity(params), 2, w(params), "*"),  # = getSSB()
             value_name = "SSB", units = "g")   # pass the whole product as weighting
# no dw, no bin-averaging by hand, no size-grid subsetting: sizeIntegral does it
ArraySpeciesBySize(x, params = params, representation = "average")  # size-resolved
bin_average_weight(K, params)   # the primitive, if you are not doing an integral
encounter_kernel(params)        # kernel getEncounter() uses; NOT pred_kernel()

# ── Plot any array directly, plus combine / compare tools ─────────────────────
plot(getResourceMort(params))   # any get*() array plots directly
p <- plot(getBiomass(sim), species = "Cod")
addPlot(p, getBiomass(sim), species = "Herring", linetype = "dashed")  # add lines
plot2(getFMort(params), getFMort(params2), "Before", "After")  # compare arrays
plotRelative(getEGrowth(params), getEGrowth(params2))          # relative diff
plotHover(getBiomass(sim))      # interactive (hover) version of an array plot

# ── Size spectra and other densities ──────────────────────────────────────────
plotSpectra(sim)        # abundance spectra vs size (+ resource & background)
plotCDF(sim)            # cumulative biomass/abundance over size
animate(sim)            # animate spectra through time
plotSpectra(sim, biomass = TRUE)                     # biomass rather than number
plotSpectra(sim, per_log_size = TRUE)                # density per log size
plotSpectra(sim, size_axis = "l")                    # x axis in length, not weight
plotSpectra(sim, log_x = TRUE)   # display only: does NOT change the y density

# ── Compare two simulations or models ─────────────────────────────────────────
plotSpectra2(params, params2, "Before", "After")
plotSpectraRelative(params, params2)      # relative difference of spectra
plotCDF2(sim, sim2, "Unfished", "Fished")

# ── Dedicated plot functions ──────────────────────────────────────────────────
# Each plot*() is a shortcut for plot() on the matching get*() array, and each has
# an interactive plotly*() twin (plotlyBiomass(), plotlySpectra(), …).
plot(sim)               # 5-panel summary
plotBiomass(sim)        # biomass vs time
plotYield(sim)          # yield vs time
plotYieldGear(sim)      # yield vs time, faceted by gear
plotFeedingLevel(sim)   # feeding level vs size
plotPredMort(sim)       # predation mortality vs size
plotFMort(sim)          # fishing mortality vs size
plotGrowthCurves(sim)   # size vs age
plotDiet(params, species = "Cod")  # diet composition vs size


Try the mizer package in your browser

Any scripts or data that you put into this service are public.

mizer documentation built on Aug. 31, 2026, 5:08 p.m.