lines.dfunc: lines.dfunc - Line plotting method for distance functions

View source: R/lines.dfunc.R

lines.dfuncR Documentation

lines.dfunc - Line plotting method for distance functions

Description

Line plot method for objects of class 'dfunc' that adds distance functions to an existing plot.

Usage

## S3 method for class 'dfunc'
lines(x, newdata = NULL, prob = NULL, ...)

Arguments

x

An estimated detection function object, normally produced by calling dfuncEstim.

newdata

A data frame containing new values of the covariates at which to evaluate the distance functions. If newdata is NULL, distance functions are evaluated at values of the observed covariates and results in one prediction per distance or transect (see parameter type). If newdata is not NULL and the model does not contains covariates, this routine returns one prediction for each row in newdata, but columns and values in newdata are ignored.

prob

Logical scalar for whether to scale the distance function to be a density function (integrates to one). Default behavior is designed to be compatible with the plot method for distance functions (plot.dfunc). By default, line transect distance functions are not scaled to a density and integrate to the effective strip width. In contrast, point transects distance functions are scaled to be densities by default.

...

Parameters passed to lines.default that control attributes like color, line width, line type, etc.

Value

A data frame containing the x and y coordinates of the plotted line(s) is returned invisibly. X coordinates in the return are names x. Y coordinates in the return are named y1, y2, ..., yn, i.e., one column per returned distance function.

See Also

dfuncEstim, plot.dfunc, print.abund

Examples

set.seed(87654)
x <- rnorm(1000, mean=0, sd=20)
x <- x[x >= 0]
x <- units::set_units(x, "mi")
Df <- data.frame(transectID = "A"
               , distance = x
                ) |> 
  dplyr::nest_by( transectID
               , .key = "detections") |> 
  dplyr::mutate(length = units::set_units(100,"km"))              
attr(Df, "detectionColumn") <- "detections"
attr(Df, "obsType") <- "single"
attr(Df, "transType") <- "line"
attr(Df,'effortColumn') <- "length"
is.RdistDf(Df)  # TRUE

dfunc <- Df |> dfuncEstim(distance ~ 1, likelihood="halfnorm")
plot(dfunc, nbins = 40, col="lightgrey", border=NA, vertLines=FALSE)
lines(dfunc, col="grey30", lwd=15)
lines(dfunc, col="grey90", lwd=5, lty = 2)

# Multiple lines 
data(sparrowDfuncObserver)
obsLevs <- levels(sparrowDfuncObserver$data$observer)
plot(sparrowDfuncObserver
   , vertLines = FALSE
   , lty = 0
   , plotBars = FALSE
   , main="Detection by observer"
   , legend = FALSE)
y <- lines(sparrowDfuncObserver
   , newdata = data.frame(observer = obsLevs)
   , col = palette.colors(length(obsLevs))
   , lty = 1
   , lwd = 4)
head(y) # values returned, with distances as column



Rdistance documentation built on April 12, 2025, 1:12 a.m.