Plot method for parametric line and point transect distance functions.
# S3 method for dfunc.para
plot(
x,
include.zero = FALSE,
nbins = "Sturges",
newdata = NULL,
legend = TRUE,
vertLines = TRUE,
plotBars = TRUE,
circles = FALSE,
density = -1,
angle = 45,
xlab = NULL,
ylab = NULL,
border = TRUE,
col = "grey85",
col.dfunc = NULL,
lty.dfunc = NULL,
lwd.dfunc = NULL,
...
)
The input distance function is returned, with two additional
components than can be used to reconstruct the plotted bars. (To
obtain values of the plotted distance functions, use predict
with type = "distances"
.)
The additional components are:
A vector containing the scaled bar heights drawn on the plot.
A vector or scalar of the bar widths drawn on the plot, with measurement units.
Re-plot the bars with barplot( return$barHeights,
width = return$barWidths )
.
An estimated detection function object, normally
produced by calling dfuncEstim
.
Boolean value specifying whether to include 0 on the x-axis
of the plot. A value of TRUE will include 0 on the left hand end of the x-axis
regardless of the range of distances. A value of FALSE will plot only the
observation strip (w.lo
to w.hi
).
Internally, this function uses hist
to compute histogram
bars for the plot. This argument is the breaks
argument to
hist
. This can be either a vector giving the breakpoints between
bars, the suggested number of bars (a single number), a string naming
an algorithm to compute the number of bars, or a function to compute the
number of bars. See hist
for all options.
Data frame (similar to newdata
parameter
of lm
) containing new values for covariates in
the distance function.
One distance function is computed and plotted for each row in the data frame.
If newdata
is NULL, a single distance function is plotted
for mean values of all numeric covariates and mode values for all
factor covariates.
Logical scalar for whether to include a legend. If TRUE, a legend will be included on the plot detailing the covariate values used to generate the plot.
Logical scalar specifying whether to plot vertical
lines at w.lo
and w.hi
from 0 to the
distance function.
Logical scalar for whether to plot the histogram of distances behind the distance function. If FALSE, no histogram is plotted, only the distance function line(s).
Logical scalar requesting the location of detection distances be plotted. If TRUE, open circles are plotted at predicted distance function heights associated with all detection distances. For computational simplicity, all distances are plotted for EVERY covariate class even though observed distances belong to only one covariate class. If FALSE, circles are not plotted.
If plotBars=TRUE
, a vector giving the density of
shading lines, in lines per inch, for the bars underneath
the distance function, repeated as necessary to exceed the number
of bars. Values of NULL or a number strictly less than 0
mean solid fill using colors from parameter col
.
If density = 0
, bars are not filled and only the borders are rendered.
If density
> 0, bars are shaded with colors and angles from
parameters col
and angle
.
When density
> 0, the slope of bar shading lines,
given as an angle in degrees (counter-clockwise), repeated as necessary
to exceed the number of bars.
Label for the x-axis
Label for the y-axis
The color of bar borders when bars are plotted,
repeated as necessary to exceed the number of bars. A
value of NA or FALSE means no borders. If bars are shaded with lines
(i.e., density>0
), border = TRUE
uses the same
color for the border as for the shading lines. Otherwise, fill color
or shaded line color are specified in col
while
border color is specified in border
.
A vector of bar fill colors or line colors when bars are
drawn and density != 0
, repeated as necessary to exceed the number
of bars. Also used for the bar borders when
border = TRUE
.
Color of the distance function(s).
If only one distance function (one line) is being plotted,
the default color is "red".
If covariates or newdata
are present,
the default value uses graphics::rainbow(n)
,
where n
is the number
of plotted distance functions. Otherwise, col.dfunc
is replicated to the required length. Plot all
distance functions in the same color by setting
col.dfunc
to
a scalar. Plot blue-red pairs of distance functions
by setting col.dfunc
= c("blue", "red")
. Etc.
Line type of the distance function(s).
If covariates or newdata
is present,
the default uses line types
to 1:n
, where n
is the number
of plotted distance functions. Otherwise, lty.dfunc
is replicated to the required length. Plot solid lines
by specifying lty.dfunc = 1
. Plot solid-dashed line pairs
by specifying lty.dfunc = c(1,2)
. Etc.
Line width of the distance function(s), replicated to the required length. Default is 2 for all lines.
When bars are plotted, this routine
uses graphics::barplot
to draw the
plotting region and bars. When bars are not plotted,
this routine sets up the plot with graphics::plot
.
... can be any argument to barplot
or plot
EXCEPT
width
, ylim
, xlim
,
density
, angle
, and space
. For example,
set the main title with main = "Main Title"
.
plot.dfunc
# Example data
set.seed(87654)
x <- rnorm(1000, mean=0, sd=20)
x <- x[x >= 0]
x <- units::set_units(x, "ft")
Df <- data.frame(transectID = "A"
, distance = x
) |>
dplyr::nest_by( transectID
, .key = "detections") |>
dplyr::mutate(length = units::set_units(1,"mi"))
attr(Df, "detectionColumn") <- "detections"
attr(Df, "obsType") <- "single"
attr(Df, "transType") <- "line"
attr(Df, "effortColumn") <- "length"
is.RdistDf(Df) # TRUE
# Estimation
dfunc <- dfuncEstim(Df
, formula = distance~1
, likelihood="halfnorm")
plot(dfunc)
plot(dfunc, nbins=25)
Run the code above in your browser using DataLab