Plots the distribution of summarised sound levels across frequency, either as lines of quantile levels or a heatmap showing the full distribution. Multiple PSD sources can be combined and plotted as long as they have identical frequency levels.
plotPSD(
x,
style = c("quantile", "density"),
scale = c("log", "linear"),
q = 0.5,
color = "black",
freqRange = NULL,
dbRange = NULL,
dbInt = 1,
densityRange = NULL,
units = "dB re: 1uPa^2/Hz",
cmap = viridis_pal()(25),
by = NULL,
referenceLevel = NULL,
facet = NULL,
ncol = NULL,
title = NULL,
returnData = FALSE,
progress = TRUE
)prepPSDData(
x,
freqRange = NULL,
style = c("density", "quantile"),
by = NULL,
dbInt = 1,
compression = 10000,
progress = TRUE
)
a ggplot object for plotPSD
, see details for prepPSDData
a dataframe or list of dataframes, or file path or vector
of file paths, or the output from prepPSDData
character specifying plot style to create, either "quantile", "density", or a vector with both
scale to use for frequency axis, one of "log" or "linear"
quantile to plot
color for quantile
range of frequencies to plot
range of dB values to plot
bin interval size for density plot
optional range of values for density color scale
units for dB axis of plot
color map to use for density plot
optional column to plot different quantile lines by, only affects
style='quantile'
. If x
is a data.frame, by
can also
be one of 'hour'
, 'month'
, or 'year'
and that column
will be created automatically if not present.
only used together with by
. A value of the
by
column to use as a reference for all other levels. The plot
will then show the difference between the other levels and the reference
optional column to facet the plots by
number of columns to use when plotting with facet
optional title for plot
if TRUE
then no plot will be generated, instead the
dataframe that would normally be used to make the plot will be returned
logical flag to show progress bar
compression factor for tdigest, lower
values are less accurate but will compute faster. Only relevant for
style='quantile'
when loading and combining multiple datasets
Taiki Sakai taiki.sakai@noaa.gov
prepPSDData
is called by the plotting code, and
does not necessarily need to be called separately from
plotPSD
. Loading PSD data can be time consuming, so
it may be useful to load the data first, then it is easier
to spend time adjusting plot settings.
The output of prepPSDData
is a list with 5 elements:
- the frequency values of the input data
- the value of the "freqRange" parameter if it was supplied
- the dB values of breakpoints used for "density" plotting
- the data used for quantile plots. These are stored as "tidgest" objects serialized using as.list.tdigest, from which quantiles can be computed
- the data used fro quantile plots. These are stored as a matrix of bin counts - each column corresponds to the "frequency" output, each row corresponds to bins defined using "dbVals" as boundaries
psd <- loadSoundscapeData(system.file('extdata/PSDSmall.csv', package='PAMscapes'))
# Plotting only first 1000 columns for brevity
plotPSD(psd[1:1000], style='density')
plotPSD(psd[1:1000], style='quantile', q=.05)
Run the code above in your browser using DataLab