ggspectro | R Documentation |
This function returns a ggplot object to draw a spectrogram
with the package ggplot2. This is an alternative to spectro
.
ggspectro(wave, f, tlab = "Time (s)",
flab = "Frequency (kHz)", alab = "Amplitude\n(dB)\n", ...)
wave |
an R object. |
f |
sampling frequency of |
tlab |
label of the time axis. |
flab |
label of the frequency axis. |
alab |
label of the amplitude axis. |
... |
other non-graphical arguments to be passed to spectro
( |
This function return the fist layer (data and aesthetic
mapping) of a ggplot2 plot.
See the example section to understand how to build a spectrogram and consult ggplot2 help to get what you
exactly need.
There is no way to plot the oscillogram as spectro does.
A ggpot layer.
This function requires ggplot2 package.
Jerome Sueur
Wickham H (2009) – ggplot2: elegant graphics for data analysis. UseR! Springer.
spectro
, spectro3D
, dynspec
## Not run:
require(ggplot2)
## first layer
v <- ggspectro(tico, ovlp=50)
summary(v)
## using geom_tile ##
v + geom_tile(aes(fill = amplitude)) + stat_contour()
## coordinates flip (interest?)
v + geom_tile(aes(fill = amplitude)) + stat_contour() + coord_flip()
## using stat_contour ##
# default (not nice at all)
v + stat_contour(geom="polygon", aes(fill=..level..))
# set up to 30 color levels with the argument bins
(vv <- v + stat_contour(geom="polygon", aes(fill=..level..), bins=30))
# change the limits of amplitude and NA values as transparent
vv + scale_fill_continuous(name="Amplitude\n(dB)\n", limits=c(-30,0), na.value="transparent")
# Black-and-white theme
(vv + scale_fill_continuous(name="Amplitude\n(dB)\n", limits=c(-30,0),
na.value="transparent", low="white", high="black") + theme_bw())
# Other colour scale (close to spectro() default output)
v + stat_contour(geom="polygon", aes(fill=..level..), bins=30)
+ scale_fill_gradientn(name="Amplitude\n(dB)\n", limits=c(-30,0),
na.value="transparent", colours = spectro.colors(30))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.