This function generates a power spectrum plot using ggplot2
based on the
provided waveform object (wave
). The plot can display normalized amplitude
values on both dB and linear scales, and includes options for customizing the
display of the carrier frequency, bandwidth, and other spectral details.
Usage
spectrum_ggplot(
wave,
auto_wl = TRUE,
wl = NULL,
ovlp = 75,
ymin = -100,
y_breaks = c(-40, -20, 0),
x_breaks = 6,
y_position = "left",
x_position = "bottom",
flip = FALSE,
color_db = "#4d4d4d",
color_linear = "#000000",
color_carrier = "#1e90ff",
color_threshold = "#228b22",
color_bandwidth = "#228b22",
fun = "mean",
wn = "blackman",
show_x_title = TRUE,
show_y_title = TRUE,
add_params = FALSE,
add_summary = TRUE,
plot_title = "",
italic_title = FALSE,
fmin = 0,
fmax = NULL,
linewidth = 1,
total_bandwidth = FALSE,
show_lines = FALSE
)
Arguments
- wave
A Wave object (from
tuneR
package), representing the sound waveform.- auto_wl
Logical. If
TRUE
, the window length (wl
) is automatically calculated based on the sampling rate of the waveform.- wl
Numeric. Window length for the FFT. Ignored if
auto_wl
isTRUE
.- ovlp
Numeric. Overlap between windows in percentage (0 to 100). Default is 75.
- ymin
Numeric. Minimum value for the y-axis (used when plotting in dB scale).
- y_breaks
Numeric vector. Break points for the y-axis in the dB scale plot.
- x_breaks
Integer. Number of breaks for the x-axis (frequency).
- y_position
Character. Position of the y-axis: "left" or "right".
- x_position
Character. Position of the x-axis: "bottom" or "top".
- flip
Logical. If
TRUE
, flips the x and y axes.- color_db
Character. Color for the dB scale plot.
- color_linear
Character. Color for the linear scale plot.
- color_carrier
Character. Color for the carrier frequency line.
- color_threshold
Character. Color for the threshold line.
- color_bandwidth
Character. Color for the bandwidth lines.
- fun
Character. Summary function for calculating the power spectrum, default is "mean".
- wn
Character. Windowing function for the FFT. Default is "blackman".
- show_x_title
Logical. If
TRUE
, displays the x-axis title.- show_y_title
Logical. If
TRUE
, displays the y-axis title.- add_params
Logical. If
TRUE
, adds parameter information (window size, overlap, etc.) to the plot.- add_summary
Logical. If
TRUE
, adds spectral summary statistics (entropy, flatness, carrier frequency, bandwidth) to the plot.- plot_title
Character. Title for the plot.
- italic_title
Logical. If
TRUE
, italicizes the plot title.- fmin
Numeric. Minimum frequency to display (in kHz).
- fmax
Numeric. Maximum frequency to display (in kHz). If
NULL
, defaults to half the sampling rate (Nyquist frequency).- linewidth
Numeric. Line width for the carrier and bandwidth lines.
- total_bandwidth
Logical. If
TRUE
, calculates the total bandwidth using a threshold of 0.1.- show_lines
Logical. If
TRUE
, displays lines for the carrier frequency and bandwidth.