Chapter 6 musicnotationR
musicnotationR is an R package for producing music notation social graphs. Currently there is one main function, musicnot()
which can be used to plot temporally organized social interaction data according to the musical notation visualization method of Ivan Chase (2006) “Music notation: a new method for visualizing social interaction in animals and humans”, Frontiers Zoology 3: 18.
6.1 Installation
The package can be installed directly from GitHub using the install_github
function from the devtools
library.
library(devtools)
install_github('jalapic/musicnotationR', username = "jalapic")
library(musicnotationR)
6.1.1 Sample Data Sets
There are currently two example datasets - ‘dom’ and ‘flies’. The format of these dataframes are as follows:
head(dom)
## Time Winner Loser behavior
## 1 1 A H peck
## 2 2 A I peck
## 3 3 A I peck
## 4 4 A D peck
## 5 5 A H peck
## 6 6 A E peck
head(flies)
## Time fly1 fly2 behavior
## 1 0.00 George Raymond push
## 2 0.14 Ivan George push
## 3 0.30 George Ivan push
## 4 0.45 Raymond Ivan poke
## 5 0.54 George Ivan tease
## 6 0.63 Vladimir Raymond poke
As can be seen, each dataframe consists of four variables. These are in order:
- col1: a numeric unit of time at which each behavior occured
- col2: the individual performing/directing the behavior
- col3: the individual receiving the behavior
- col4: the behavior
Important notes: The first three columns have to be included in that order, however, they can be named anything. If behavior is included it has to be in the fourth column, but again can be named anything. As many other variables/columns as desired can be included in the dataframe and they won’t interfere with graphing.
For instance, the following randomly generated data are also in an acceptable format:
set.seed(84)
<- random_datetime(100, st="2015/01/01", et="2015/01/31")
datetime <- matrix(replicate(100, sample(LETTERS[1:6], 2)), ncol=2, byrow=T)
indivs
<- data.frame(datetime, indivs)
mydf colnames(mydf) <- c("datetime", "indiv1", "indiv2")
head(mydf)
## datetime indiv1 indiv2
## 1 2015-01-01 04:06:48 F D
## 2 2015-01-01 08:31:25 C D
## 3 2015-01-01 15:03:32 C D
## 4 2015-01-02 22:29:50 B A
## 5 2015-01-03 00:15:26 C F
## 6 2015-01-03 06:05:46 E C
The datetime variable above is generated randomly between a start and end date using the random_datetime
function built in to the musicnotationR package.
6.1.3 Further customization of music notation plots
Because the musicnot()
function is essentially a wrapper for ggplot2
code, each plot can be further altered by adding ggplot2
code. For instance,
<- musicnot(flies, gridcolor=T, gridlinesize = 0.5, labels="name",
p colors=c("black", "orange1", "limegreen", "dodgerblue1"))
+
p ggtitle("Social Interactions of Flies") +
xlab("Time in seconds") +
theme(panel.background = element_rect(fill = "mistyrose1"),
panel.grid.minor = element_blank()
)