plot.dfunc | R Documentation |
Plot method for objects of class 'dfunc
'. Objects of
class 'dfunc
' are estimated distance functions produced by
dfuncEstim
.
## S3 method for class 'dfunc'
plot(
x,
include.zero = FALSE,
nbins = "Sturges",
newdata = NULL,
legend = TRUE,
vertLines = TRUE,
plotBars = TRUE,
density = -1,
angle = 45,
xlab = NULL,
ylab = NULL,
border = TRUE,
col = "grey85",
col.dfunc = NULL,
lty.dfunc = NULL,
lwd.dfunc = NULL,
...
)
x |
An estimated distance function resulting from a call to
|
include.zero |
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
input distance range ( |
nbins |
Internally, this function uses |
newdata |
Data frame similar to the |
legend |
Logical scalar for whether to include a legend. If TRUE, a legend will be included on the plot detailing the covariate values use to generate the plot. |
vertLines |
Logical scalar specifying whether to plot vertical
lines at |
plotBars |
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). |
density |
If |
angle |
When |
xlab |
Label for the x-axis |
ylab |
Label for the y-axis |
border |
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., |
col |
A vector of bar fill colors or line colors when bars are
drawn and |
col.dfunc |
Color of the distance function(s).
If only one distance function (one line) is being plotted,
the default color is "red".
If covariates or |
lty.dfunc |
Line type of the distance function(s).
If covariates or |
lwd.dfunc |
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 |
If plotBars
is TRUE, a scaled histogram is plotted
and the estimated distance function
is plotted over the top of it. When bars are plotted,
this routine uses graphics::barplot
for setting up the initial plotting region and
most parameters to graphics::barplot
can
be specified (exceptions noted above in description of '...').
The form of the likelihood and any series
expansions is printed in the main title (overwrite this with
main="<my title>"
). Convergence of the distance
function is checked. If the distance function did not converge, a warning
is printed over the top of the histogram. If one or more parameter
estimates are at their limits (likely indicating non-convergence or poor
fit), another warning is printed.
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:
barHeights |
A vector containing the scaled bar heights drawn on the plot. |
barWidths |
A vector or scaler of the bar widths drawn on the plot, with measurement units. |
Re-plot the bars with barplot( return$barHeights,
width = return$barWidths )
.
dfuncEstim
, print.dfunc
,
print.abund
set.seed(87654)
x <- rnorm(1000, mean=0, sd=20)
x <- x[x >= 0]
x <- units::set_units(x, "ft")
dfunc <- dfuncEstim(x~1, likelihood="halfnorm")
plot(dfunc)
plot(dfunc, nbins=25)
# showing effects of plot params
plot(dfunc
, col=c("red","blue","orange")
, border="black"
, xlab="Off-transect distance"
, ylab="Prob"
, vertLines = FALSE
, main="Showing plot params")
plot(dfunc
, col="wheat"
, density=30
, angle=c(-45,0,45)
, cex.axis=1.5
, cex.lab=2
, ylab="Probability")
plot(dfunc
, col=c("grey","lightgrey")
, border=NA)
plot(dfunc
, col="grey"
, border=0
, col.dfunc="blue"
, lty.dfunc=2
, lwd.dfunc=4
, vertLines=FALSE)
plot(dfunc
, plotBars=FALSE
, cex.axis=1.5
, col.axis="blue")
rug(dfunc$detections$dist)
# Plot showing f(0)
hist(dfunc$detections$dist
, n = 40
, border = NA
, prob = TRUE)
x <- seq(dfunc$w.lo, dfunc$w.hi, length=200)
y <- predict(dfunc, type="dfunc", distances = x)
lines(x, c(y)/attr(y, "scaler"))
c(attr(y,"scaler") / y[1], ESW(dfunc)) # 1/f(0) = ESW
# Covariates: detection by observer
data(sparrowDetectionData)
data(sparrowSiteData)
dfuncObs <- dfuncEstim(formula = dist ~ observer + groupsize(groupsize)
, likelihood = "hazrate"
, detectionData = sparrowDetectionData
, siteData = sparrowSiteData)
plot(dfuncObs
, newdata = data.frame(observer = levels(sparrowSiteData$observer))
, vertLines = FALSE
, lty = c(1,1)
, col.dfunc = heat.colors(length(levels(sparrowSiteData$observer)))
, col = c("grey","lightgrey")
, border=NA
, main="Detection by observer")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.