<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/spectrograms-in-r-a-gallery/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://walczak.org/2018/09/spectrograms-in-r-a-gallery/"> R-bloggers – Eryk Walczak</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Creating a <a rel="nofollow" href="https://en.wikipedia.org/wiki/Spectrogram" target="_blank">spectrogram</a> is a basic step in every analysis of audio signals. Spectrograms visualise how frequencies change over a time period. Luckily, there is a selection of R packages that can help with this task. I will present a selection of packages that I like to use. This post is not an introduction to spectrograms. If you want to learn more about them then try other resources (e.g. <a rel="nofollow" href="https://www.phon.ucl.ac.uk/courses/spsci/acoustics/week1-10.pdf" target="_blank">lecture notes</a> from UCL).</p>
<p>The examples shown below came mostly from the official documentation and were kept as simple as possible. The majority of functions allow further customisation of the plots.</p>
<p><a rel="nofollow" href="https://cran.r-project.org/web/packages/phonTools/index.html" target="_blank">phonTools</a></p>
<p>View the code on <a rel="nofollow" href="https://gist.github.com/erzk/bff84ae4295f396116a95029c6fdf8fa" target="_blank">Gist</a>.</p>
<p><a rel="nofollow" href="https://i0.wp.com/walczak.org/wp-content/uploads/2018/09/phonTools_spectrogram_R.png?ssl=1" target="_blank"><img sizes="(max-width: 600px) 100vw, 600px" src="https://i0.wp.com/walczak.org/wp-content/uploads/2018/09/phonTools_spectrogram_R.png?w=450&ssl=1" alt="" class="wp-image-622" data-recalc-dims="1"></a></p>
<p><a rel="nofollow" href="https://cran.r-project.org/web/packages/seewave/index.html" target="_blank">seewave</a></p>
<p>View the code on <a rel="nofollow" href="https://gist.github.com/erzk/c419edc571d02f1ed7c3712046fd72b8" target="_blank">Gist</a>.</p>
<p><a rel="nofollow" href="https://i1.wp.com/walczak.org/wp-content/uploads/2018/09/seewave_spectrogram_R.png?ssl=1" target="_blank"><img sizes="(max-width: 600px) 100vw, 600px" src="https://i1.wp.com/walczak.org/wp-content/uploads/2018/09/seewave_spectrogram_R.png?w=450&ssl=1" alt="" class="wp-image-624" data-recalc-dims="1"></a></p>
<p><a rel="nofollow" href="https://cran.r-project.org/web/packages/seewave/index.html" target="_blank">seewave</a> and <a rel="nofollow" href="https://cran.r-project.org/web/packages/ggplot2/index.html" target="_blank">ggplot2</a></p>
<p>View the code on <a rel="nofollow" href="https://gist.github.com/erzk/67757c0bf8ae936a7da422aa36764366" target="_blank">Gist</a>.</p>
<p><a rel="nofollow" href="https://i0.wp.com/walczak.org/wp-content/uploads/2018/09/seewave_ggplot2_spectrogram_R.png?ssl=1" target="_blank"><img alt="" src="https://i0.wp.com/walczak.org/wp-content/uploads/2018/09/seewave_ggplot2_spectrogram_R.png?w=450&ssl=1" class="wp-image-623" data-recalc-dims="1"></a></p>
<p><a rel="nofollow" href="https://cran.r-project.org/web/packages/signal/index.html" target="_blank">signal</a></p>
<p>View the code on <a rel="nofollow" href="https://gist.github.com/erzk/85bddaa15f6a5fd780c1d49c2d64e47e" target="_blank">Gist</a>.</p>
<p><a rel="nofollow" href="https://i2.wp.com/walczak.org/wp-content/uploads/2018/09/signal_spectrogram_R.png?ssl=1" target="_blank"><img sizes="(max-width: 600px) 100vw, 600px" src="https://i2.wp.com/walczak.org/wp-content/uploads/2018/09/signal_spectrogram_R.png?w=450&ssl=1" alt="" class="wp-image-625" data-recalc-dims="1"></a></p>
<p><a rel="nofollow" href="https://cran.r-project.org/web/packages/soundgen/index.html" target="_blank">soundgen</a></p>
<p>View the code on <a rel="nofollow" href="https://gist.github.com/erzk/e114baf74913108feb3c8906de0e1918" target="_blank">Gist</a>.</p>
<p><a rel="nofollow" href="https://i0.wp.com/walczak.org/wp-content/uploads/2018/09/soundgen_spectrogram_R.png?ssl=1" target="_blank"><img sizes="(max-width: 600px) 100vw, 600px" src="https://i0.wp.com/walczak.org/wp-content/uploads/2018/09/soundgen_spectrogram_R.png?w=450&ssl=1" alt="" class="wp-image-626" data-recalc-dims="1"></a></p>
<p><a rel="nofollow" href="https://cran.r-project.org/web/packages/warbleR/index.html" target="_blank">warbleR</a></p>
<p>View the code on <a rel="nofollow" href="https://gist.github.com/erzk/b3cddfe92fe74662f6658d71d5d665ad" target="_blank">Gist</a>.</p>
<p><a rel="nofollow" href="https://i1.wp.com/walczak.org/wp-content/uploads/2018/09/Phae.long1_.wav-1.jpeg?ssl=1" target="_blank"><img sizes="(max-width: 640px) 100vw, 640px" src="https://i0.wp.com/walczak.org/wp-content/uploads/2018/09/Phae.long1_.wav-1-1024x1024.jpeg?w=450&ssl=1" alt="" class="wp-image-621" data-recalc-dims="1"></a></p>
<p><a rel="nofollow" href="https://cran.r-project.org/web/packages/hht/index.html" target="_blank">hht</a></p>
<p>View the code on <a rel="nofollow" href="https://gist.github.com/erzk/6fa4a88eef6e35c08d9a674ae6efe488" target="_blank">Gist</a>.</p>
<p><a rel="nofollow" href="https://i1.wp.com/walczak.org/wp-content/uploads/2018/09/hht_spectrogram_R.png?ssl=1" target="_blank"><img sizes="(max-width: 750px) 100vw, 750px" src="https://i1.wp.com/walczak.org/wp-content/uploads/2018/09/hht_spectrogram_R.png?w=450&ssl=1" alt="" class="wp-image-620" data-recalc-dims="1"></a></p>
<p>Creating a spectrogram from the scratch is not so difficult, as shown by Hansen Johnson in <a rel="nofollow" href="https://hansenjohnson.org/post/spectrograms-in-r/" target="_blank">this blog post</a>. Another <a rel="nofollow" href="https://github.com/usagi5886/dsp/blob/master/Spectrogram().r" target="_blank">solution</a> was provided by Aaron Albin.</p>
<p>View the code on <a rel="nofollow" href="https://gist.github.com/erzk/89247b920d5536dbf3f36ab7c2b6c2af" target="_blank">Gist</a>.</p>
<p><a rel="nofollow" href="https://i1.wp.com/walczak.org/wp-content/uploads/2018/09/Spectrogram_R.png?ssl=1" target="_blank"><img sizes="(max-width: 600px) 100vw, 600px" src="https://i1.wp.com/walczak.org/wp-content/uploads/2018/09/Spectrogram_R.png?w=450&ssl=1" alt="" class="wp-image-627" data-recalc-dims="1"></a></p>
<p><a rel="nofollow" href="http://www.fon.hum.uva.nl/praat/" target="_blank">Praat</a> is a workhorse of audio analysis. It is a standalone software, but there is also an R controller called <a rel="nofollow" href="http://aaronalbin.com/praatr/index.html" target="_blank">PraatR</a>, that allows calling Praat functions from R. It is not the easiest tool to use so I will just mention it here for reference.</p>
<p>I am pretty sure that there are more packages that allow creating spectrograms but I had to stop somewhere. Feel free to leave comments about other examples.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://walczak.org/2018/09/spectrograms-in-r-a-gallery/"> R-bloggers – Eryk Walczak</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/waJ8zgIKF_o" height="1"></a></div>