email: jc3181 AT columbia DOT edu
An R package for producing music notation social graphs
This package is in its very early stages. Currently there is one main function, musicnot() which can be used to plot temporally organized social interation 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.
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)
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:
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)
datetime <- random_datetime(100, st="2015/01/01", et="2015/01/31")
indivs <- matrix(replicate(100, sample(LETTERS[1:6], 2)), ncol=2, byrow=T)
mydf <- data.frame(datetime, indivs)
colnames(mydf) <- c("datetime", "indiv1", "indiv2")
head(mydf)
## datetime indiv1 indiv2
## 1 2015-01-01 05:06:48 D A
## 2 2015-01-01 09:31:25 A F
## 3 2015-01-01 16:03:32 E C
## 4 2015-01-02 23:29:50 F C
## 5 2015-01-03 01:15:26 E D
## 6 2015-01-03 07:05:46 E A
The datetime variable above is generated randomly between a start and end date using the random_datetime function built in to the musicnotationR package.
Because the musicnot() function is essentially a wrapper for ggplot2 code, each plot can be further altered by adding ggplot2 code. For instance,
p <- musicnot(flies, gridcolor=T, gridlinesize = 0.5, labels="name", 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()
)