playitbyr Getting Started Support--Help, Bugs, and Documentation GitHub Sonification Resources

shape_scatter {playitbyr}R Documentation

Create a scatterplot layer

Description

Creates a scatterplot layer; the audio analogue of ggplot2's geom_point.

Usage

  shape_scatter(jitter = 0, relative = TRUE, ...,
    data = NULL, mapping = NULL)

Arguments

jitter

The maximum size, in seconds, of how much to jitter time by when there are multiple notes at the same pitch and time (the sonic equivalent of overplotting). The default, 0, means no jitter occurs.

relative

Make the duration relative to the overall length of the sonification? The default, TRUE, means that the sonification will scale durations relative to the length of the overall sonification (it estimates how long a “beat” is and then rescales duration in relation to that). Otherwise, durations remain constant even if the sonification is much longer or shorter (which may mean that note durations must be fiddled with so they don't overlap).

...

settings to pass to sonlayer (see Details)

data

The data.frame to be sonified for this layer. If blank, the data from the parent sonify object is used.

mapping

A sonaes object.

Details

The audio scatterplot is implemented by a simple frequency-modulation synthesis (through Csound). The following parameters are available for setting or mapping:

time

The starting time of the note (in seconds).

pitch

The pitch of the note, in the Csound oct notation notation for pitches, where 8 is middle C and 1 represents an octave, to the corresponding frequency in Hertz. By default this is scaled to the nearest musical (chromatic) pitch. (See scale_pitch_continuous.)

dur

The duration of the note (relative to the total time if relative = TRUE, in seconds otherwise).

amp

The volume of the note, as a proportion between 0 and 1, where 1 is the maximum volume. Note that a multiple notes that happen at the same time could add up to more than one, causing distortion and clipping.

attkp

The proportion of the note's length devoted to the initial (linear) attack.

decayp

The proportion of the note's length devoted to the (linear) decay.

indx

The index of modulation. This affects the distortion of the tone; indx = 0 is a sine wave, whereas higher indices of modulation give increasingly complex tones.

mod

The modulating frequency, given as a multiple of the primary frequency (i.e. given by pitch).

To set a sound parameter to a value, you simply include it as an extra argument in shape_scatter; to map a parameter, you set the mapping for the layer or the sonify object using sonaes (see examples).

Value

A sonlayer object that can be added onto a sonify object.

Examples

x1 <- sonify(iris, sonaes(time = Petal.Width, pitch = Petal.Length)) +
  shape_scatter() # no jitter
## Not run: x1
x2 <- sonify(iris, sonaes(time = Petal.Width, pitch = Petal.Length)) +
  shape_scatter(jitter = 0.3) # substantial jitter, fuzzes out overlap
## Not run: x2

## relative = TRUE: rescales duration to fit overall length (usually easier to hear)
d <- cbind(airquality, row = rownames(airquality))
x3 <- sonify(d, sonaes(time = row, pitch = Temp)) + shape_scatter(dur = 3) +
  scale_time_continuous(c(0, 10))
## Not run: x3
x4 <- sonify(d, sonaes(time = row, pitch = Temp)) + shape_scatter(dur = 3) +
  scale_time_continuous(c(0, 5))
## Not run: x4

## relative = FALSE: duration is in seconds and is not scaled to fit overall length
## (creates lots of overlap)
x5 <- sonify(d, sonaes(time = row, pitch = Temp)) + shape_scatter(relative = FALSE, dur = 3) +
  scale_time_continuous(c(0, 10))
## Not run: x5
x6 <- sonify(d, sonaes(time = row, pitch = Temp)) + shape_scatter(relative = FALSE, dur = 3) +
  scale_time_continuous(c(0, 5))
## Not run: x6

## Setting the pitch equal to 8 (C), and using iris$Sepal.Width
## to generate the timings of notes##'
x7 <- sonify(iris[1:10,], sonaes(time = Sepal.Width)) + shape_scatter(pitch = 9)
## Not run: x7

## Instead, /mapping/ the pitch to 9.
x8 <- sonify(iris[1:10,], sonaes(time = Sepal.Width)) + shape_scatter(pitch = 9)
## Not run: x8
## If a value in the mapping
## is a vector and is not a name of the data column, playitbyr
## creates a new column with that value. This is then scaled,
## producing an unexpected F# (8.5) here when you might expect the same
## sound as above!