This function generates an interactive spectrum plot using Plotly, offering customizable options for windowing, overlap, amplitude shading (dB and linear), and the ability to display summary statistics and parameter annotations. The function supports both dB and linear scales, bandwidth calculations, and frequency markers.
Usage
spectrum_plotly(
wave,
freq_res = 50,
db_shade = TRUE,
ovlp = 0,
fun = "mean",
wn = "blackman",
total_bandwidth = FALSE,
limit_indices = FALSE,
plot_title = "",
italic_title = TRUE,
fmin = 0,
fmax = NULL,
add_params = FALSE,
add_summary = FALSE,
x_breaks = 10,
y_position = "left",
x_position = "bottom",
show_x_title = TRUE,
show_y_title = TRUE,
color_db = "grey",
color_linear = "black",
color_carrier = "white",
color_threshold = "white",
color_bandwidth = "white",
show_lines = FALSE,
linewidth = 1
)
Arguments
- wave
A wave object containing the audio data.
- freq_res
Numeric, the frequency resolution in Hz per bin. Default is 50.
- db_shade
Logical, whether to shade the plot based on decibel amplitude. Default is
TRUE
.- ovlp
Numeric, the overlap between successive windows in percentage. Default is 0 (no overlap).
- fun
Character, the summary function to apply to the spectrum, one of "mean", "median", "var", or "sd". Default is "mean".
- wn
Character, the window type for the FFT, one of "hanning", "bartlett", "blackman", "flattop", "hamming", or "rectangle". Default is "hanning".
- total_bandwidth
Logical, whether to calculate the total bandwidth, ignoring gaps. Default is
FALSE
.- limit_indices
Logical, whether to limit the spectrum indices to the frequency range between
fmin
andfmax
. Default isFALSE
.- plot_title
Character, the title of the plot. Default is an empty string.
- italic_title
Logical, whether to italicize the plot title. Default is
FALSE
.- fmin
Numeric, minimum frequency (in kHz) to plot. If
NULL
, the entire frequency range is plotted. Default isNULL
.- fmax
Numeric, maximum frequency (in kHz) to plot. If
NULL
, it defaults to the Nyquist frequency.- add_params
Logical, whether to add window parameters as a label on the plot. Default is
FALSE
.- add_summary
Logical, whether to add summary statistics as a label on the plot. Default is
TRUE
.- x_breaks
Numeric, the number of breaks on the x-axis (frequency axis). Default is 6.
- y_position
Character, the position of the y-axis, either "left" or "right". Default is "left".
- x_position
Character, the position of the x-axis, either "top" or "bottom". Default is "bottom".
- show_x_title
Logical, whether to show the x-axis title. Default is
TRUE
.- show_y_title
Logical, whether to show the y-axis title. Default is
TRUE
.- color_db
Character, color for the dB amplitude plot. Default is "grey30".
- color_linear
Character, color for the linear amplitude plot. Default is "black".
- color_carrier
Character, color for the carrier frequency marker. Default is "white".
- color_threshold
Character, color for the threshold line. Default is "white".
- color_bandwidth
Character, color for the bandwidth lines. Default is "white".
- show_lines
Logical, whether to show lines for the carrier frequency and bandwidths. Default is
FALSE
.- linewidth
Numeric, the width of the lines in the plot. Default is 1.