lines.dfunc | R Documentation |
Line plot method for objects of class 'dfunc
'
that adds distance functions to an existing plot.
## S3 method for class 'dfunc'
lines(x, newdata = NULL, prob = NULL, ...)
x |
An estimated detection function object, normally
produced by calling |
newdata |
A data frame containing new values of
the covariates at which to evaluate the distance functions.
If |
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
( |
... |
Parameters passed to |
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.
dfuncEstim
, plot.dfunc
,
print.abund
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.