1 Introduction

This tutorial introduces motion charts in “R”. The entire code for the sections below can be downloaded here.

2 Preparation and session set up

As all visualizations in this tutorial rely on “R”, it is necessary to install “RStudio” (a programm which makes working with R particularly user-friendly). If “RStudio” is not already installed on your machine, please search for “RStudio” in your favorite search engine and add the term “download”. Open any of the first few links and follow the installation instructions (they are easy to follow, do not require any specifications, and are pretty much self-explanatory).

In addition, we prepare our session by clearing the workspace, setting optionsinstalling certain “libraries” or “packages” that we need in this tutorial. Thus, please install the libraries by running the code below this paragraph - the installation may take some time (depending on the number and the nature of the libraries it may take a couple of minutes).

# clean current workspace
rm(list=ls(all=T))
# set options
options(stringsAsFactors = F)         # no automatic data transformation
options("scipen" = 100, "digits" = 4) # supress math annotation
# install libraries
install.packages(c("googleVis", "dplyr"))

3 Getting started with Motion Charts

To get started with motion charts, we load the “googleVis” package and use an in-built data set called “Fruits”.

# load library
library(googleVis)
# inspect fruid data set
str(Fruits)
## 'data.frame':    9 obs. of  7 variables:
##  $ Fruit   : Factor w/ 3 levels "Apples","Bananas",..: 1 1 1 3 2 3 2 3 2
##  $ Year    : num  2008 2009 2010 2008 2008 ...
##  $ Location: Factor w/ 2 levels "East","West": 2 2 2 1 1 1 1 1 1
##  $ Sales   : num  98 111 89 96 85 93 94 98 81
##  $ Expenses: num  78 79 76 81 76 80 78 91 71
##  $ Profit  : num  20 32 13 15 9 13 16 7 10
##  $ Date    : Date, format: "2008-12-31" "2009-12-31" ...
# create motion chart object
M <- gvisMotionChart(Fruits, idvar = "Fruit", timevar = "Year")
# display motion chart object
plot(M)

A browser window should open and and if you accept Adobe Player, then motion chart showing the population size by country should pop up. You can hoover over any country and see its population size.

The motion chart then shows changes in Sales (x-axis) and Expenses (y-axis) across time.

4 Linguistic Example: which verbs take which complement clause type?

# read in data
compdata <- read.table("D:\\R\\MapsInR/compdata.txt", sep = "\t", header = T)
# inspect data structure
str(compdata)
## 'data.frame':    660 obs. of  5 variables:
##  $ x     : num  -0.2938 -0.3893 -0.5486 0.0155 0.0874 ...
##  $ y     : num  0.135 0.232 0.312 -0.682 -0.759 ...
##  $ decade: int  1860 1860 1860 1860 1860 1860 1860 1860 1860 1860 ...
##  $ verb  : Factor w/ 44 levels "acknowledge",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ freq  : num  12.58 34.35 8.21 1.52 5.96 ...
# create motion chart object
MC <- gvisMotionChart(compdata, idvar = "verb", timevar = "decade")
# display motion chart object
plot(MC)

5 Linguistic Example: which verbs take which complement clause type?

# load data
convdata <- read.table("D:\\R\\MapsInR/convdata.txt", sep = "\t", header = T)
# inspect data structure
str(convdata)
## 'data.frame':    1785 obs. of  6 variables:
##  $ VERB      : Factor w/ 119 levels "ACCOUNT","ACT",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ DECADE    : int  1860 1870 1880 1890 1900 1910 1920 1930 1940 1950 ...
##  $ verbs     : num  40.2 42.3 40.2 38 36.8 ...
##  $ nouns     : num  141 144 128 117 127 ...
##  $ freq      : num  181 186 168 155 164 ...
##  $ skewedness: num  -100.6 -101.5 -87.4 -79.5 -90 ...
# create motion chart object
MC <- gvisMotionChart(convdata, idvar = "VERB", timevar = "DECADE")
# display motion chart object
plot(MC)
# load data
ampadjdata <- read.table("D:\\Uni\\Projekte\\02-Intensification\\AmpCOHA/collex_decade.txt", sep = "\t", header = T)
# load library
library(dplyr)
# process data
ampadjdata <- ampadjdata %>%
  select(Decade, Amp, Adjective, OBS) %>%
  rename(Frequency = OBS) %>%
  mutate(Bigram = paste(Amp, Adjective, sep = "")) %>%
  select(Decade, Bigram, Frequency)
# inspect data
head(ampadjdata)
##   Decade         Bigram Frequency
## 1   1870       otherbad         0
## 2   1870 otherbeautiful         2
## 3   1870      othergood         5
## 4   1870     otherhappy         4
## 5   1870      othernice         1
## 6   1870     otherother        34
# create motion chart
MC <- gvisMotionChart(ampadjdata, idvar = "Bigram", timevar = "Decade")
plot(MC)
intsaus <- read.table("D:\\Uni\\Projekte\\02-Intensification\\AmpAusENZE/datadf5.txt", 
                      sep = "\t", header = T)
intsaus <- intsaus[intsaus$int == 1,]
intsaus <- intsaus[intsaus$txtyp == "PrivateDialogue",]
# label infrequent amplifier as "other"
freqpinttb <- table(intsaus$pint)
freqpint <- names(freqpinttb)[which(freqpinttb >= 10)]
intsaus$pint <- as.vector(unlist(sapply(intsaus$pint, function(x){
  x <- ifelse(x %in% freqpint, x, "other")
})))
# label infrequent adjective as "other"
freqadjtb <- table(intsaus$adj)
freqadj <- names(freqadjtb)[which(freqadjtb >= 20)]
intsaus$adj <- as.vector(unlist(sapply(intsaus$adj, function(x){
  x <- ifelse(x %in% freqadj, x, "other")
})))


table(intsaus$pint)
## 
##    21    24    26    30 other 
##    31   192   105   118   137
str(intsaus)
## 'data.frame':    583 obs. of  21 variables:
##  $ id          : int  6 8 19 31 55 68 76 77 84 86 ...
##  $ flid        : Factor w/ 959 levels "<<I><#>Ah, we were in full stream, ah, concerned with these associations between invertebrate animals and algae"| __truncated__,..: 34 34 34 34 37 37 37 37 37 37 ...
##  $ sf          : Factor w/ 35 levels "<<I><#>Ah, we were in full stream, ah, concerned with these associations between invertebrate animals and algae"| __truncated__,..: 32 32 32 32 32 32 32 32 32 32 ...
##  $ spk         : Factor w/ 73 levels "<<I><#>Ah, we were in full stream, ah, concerned with these associations between invertebrate animals and algae"| __truncated__,..: 46 46 46 46 45 45 45 45 45 45 ...
##  $ gender      : Factor w/ 2 levels "F","M": 2 2 2 2 1 1 1 1 1 1 ...
##  $ edlev       : Factor w/ 1 level "college": 1 1 1 1 1 1 1 1 1 1 ...
##  $ age         : Factor w/ 5 levels "17-25","26-30",..: 2 2 2 2 NA NA NA NA NA NA ...
##  $ occupation  : Factor w/ 2 levels "acmp","sml": 1 1 1 1 NA NA NA NA NA NA ...
##  $ txtyp       : Factor w/ 4 levels "PrivateDialogue",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ birthplace  : Factor w/ 13 levels "Arrived Aust. age 4",..: NA NA NA NA NA NA NA NA NA NA ...
##  $ mothertongue: Factor w/ 1 level "English": NA NA NA NA NA NA NA NA NA NA ...
##  $ date        : Factor w/ 132 levels "1/10/92","1/11/92",..: 28 28 28 28 4 4 4 4 4 4 ...
##  $ wordcount   : int  2012 2012 2012 2012 2010 2010 2010 2010 2010 2010 ...
##  $ pint        : chr  "24" "other" "21" "other" ...
##  $ adj         : chr  "45" "45" "other" "45" ...
##  $ upcs        : Factor w/ 130 levels "aggressive","analytic",..: 45 45 48 45 110 128 61 45 63 6 ...
##  $ post1       : Factor w/ 2746 levels "'cause/,","'cause/IN",..: 2269 1669 350 236 350 350 2465 2468 1715 158 ...
##  $ strng       : Factor w/ 9453 levels "'/POS last/JJ hours/NNS were/VBD a/DT",..: 5795 3024 5530 3023 5903 3151 8825 8713 8846 2103 ...
##  $ int         : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ fun         : Factor w/ 2 levels "attributive",..: 1 1 2 1 2 2 1 1 1 2 ...
##  $ priming     : int  0 1 0 0 0 0 0 1 0 1 ...
t1 <- ftable(intsaus$pint, intsaus$adj, intsaus$age)
t1
##              17-25 26-30 31-40 41-50 51-80
##                                           
## 21    45         6     0     0     0     0
##       73         0     0     0     0     0
##       76         0     0     0     0     0
##       79         0     0     0     0     0
##       other     15     5     0     1     2
## 24    45        26     5     0     1     0
##       73         0     0     0     0     0
##       76         0     0     0     0     0
##       79        17     1     5     0     0
##       other     89    13    14     7     0
## 26    45         3     2     0     0     0
##       73        11     3     4     1     1
##       76        12     1     4     2     2
##       79         2     0     1     0     0
##       other     37     4     7     0     1
## 30    45         5     3     4     1     5
##       73         0     0     0     0     0
##       76         2     0     1     0     0
##       79         6     2     1     0     1
##       other     36    11    12     4    12
## other 45         1     2     0     0     2
##       73         0     0     0     0     0
##       76         0     0     0     0     0
##       79         0     0     0     0     0
##       other     12     7     4     1     2