plotPSD: Plot Power Spectral Density

View source: R/plotPSD.R

plotPSDR Documentation

Plot Power Spectral Density

Description

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.

Usage

plotPSD(
  x,
  style = c("quantile", "density"),
  scale = c("log", "linear"),
  q = 0.5,
  color = "black",
  lwd = 1,
  quantileBorder = TRUE,
  borderLwd = 0.5,
  alpha = 0.1,
  linetype = 1,
  freqRange = NULL,
  dbRange = NULL,
  dbInt = 1,
  densityRange = NULL,
  units = "dB re: 1uPa^2/Hz",
  cmap = viridis_pal()(25),
  by = NULL,
  referenceLevel = NULL,
  showNObs = TRUE,
  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
)

Arguments

x

a dataframe or file path or vector of file paths

style

character specifying plot style to create, either "quantile", "density", or a vector with both

scale

scale to use for frequency axis, one of "log" or "linear"

q

quantile to plot

color

color for quantile. Can be a named vector with names corresponding to values in by

lwd

line width for median line in quantile plot

quantileBorder

logical flag to show a line border at quantile boundary instead of just shading

borderLwd

line width for border lines if quantileBorder=TRUE

alpha

alpha level for the ribbon shading when plotting a quantile

linetype

line type to use for lines, multiple values can be provided for different levels if by is not NULL. See scale_linetype for accepted values. Specific ordering can be assigned by using a named vector where the name corresponds to the value in by

freqRange

range of frequencies to plot

dbRange

range of dB values to plot

dbInt

bin interval size for density plot

densityRange

optional range of values for density color scale

units

units for dB axis of plot

cmap

color map to use for density plot

by

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.

referenceLevel

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

showNObs

logical flag to show number of observations in plot legend when using by

facet

optional column to facet the plots by

ncol

number of columns to use when plotting with facet

title

optional title for plot

returnData

if TRUE then no plot will be generated, instead the dataframe that would normally be used to make the plot will be returned

progress

logical flag to show progress bar

compression

no longer used

Value

a ggplot object

Author(s)

Taiki Sakai taiki.sakai@noaa.gov

Examples


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)


PAMscapes documentation built on Oct. 3, 2026, 1:06 a.m.