-
Notifications
You must be signed in to change notification settings - Fork 3
Figure Statistics
This guide is also available as a vignette in the R console: vignette(Figure-Statistics).
- Who’s talking how much? (Tokens)
- Who’s talking how often? (Utterances)
- When are figures talking?
- When are characters mentioned?
We’re assuming here that we have loaded some texts using loadText(),
and that this text is stored as a data.frame in the variable text. For
this example, we have loaded Emilia Galotti and Romeo und Julia, both
coming from the TextGrid repository. For demo purposes, one can use the
data sets included in the package.
# Load Emilia Galotti
data(rksp.0)
# Load Miß Sara Sampson
data(rjmw.0)
text <- rbind(rksp.0$mtext, rjmw.0$mtext)First, we calculate figure statistics.
fstat <- figureStatistics(text, names=TRUE, normalize=FALSE)
summary(fstat)## corpus drama length
## Length:24 Length:24 Min. :25365
## Class :character Class :character 1st Qu.:25365
## Mode :character Mode :character Median :25365
## Mean :28040
## 3rd Qu.:31201
## Max. :31201
##
## figure tokens types utterances
## ANGELO : 1 Min. : 42.0 Min. : 34.0 Min. : 2.00
## APPIANI : 1 1st Qu.: 356.2 1st Qu.: 175.5 1st Qu.: 15.25
## BATTISTA : 1 Median :1073.5 Median : 422.0 Median : 34.50
## CAMILLO ROTA : 1 Mean :2356.9 Mean : 629.5 Mean : 63.54
## CLAUDIA GALOTTI: 1 3rd Qu.:3071.0 3rd Qu.: 829.2 3rd Qu.: 81.75
## CONTI : 1 Max. :9278.0 Max. :1927.0 Max. :221.00
## (Other) :18
## utteranceLengthMean utteranceLengthSd firstBegin lastEnd
## Min. : 7.00 Min. : 5.215 Min. : 426 Min. : 5695
## 1st Qu.:22.03 1st Qu.: 22.926 1st Qu.: 5279 1st Qu.: 52026
## Median :30.18 Median : 35.096 Median :26292 Median :112354
## Mean :32.65 Mean : 38.657 Mean :23335 Mean : 98856
## 3rd Qu.:41.70 3rd Qu.: 48.879 3rd Qu.:29466 3rd Qu.:145000
## Max. :90.65 Max. :108.893 Max. :88094 Max. :170838
##
This figure statistics table already contains all the information we need and can be inspected and analysed directly. The remaining steps are only needed if you want to plot this information as a stacked bar chart.
# Create a matrix
mat <- figurematrix(fstat)
summary(mat)## Length Class Mode
## values 28 -none- numeric
## labels 26 -none- character
## cs 28 -none- numeric
head(mat$values,5)## rjmw.0 rksp.0
## [1,] 9278 5660
## [2,] 8176 5553
## [3,] 7295 3398
## [4,] 2085 2962
## [5,] 1836 2363
mat is a list containing three things: values is a matrix storing
the number of tokens a figure speaks, labels contains the names of
figures corresponding to the respective cell in values and cs
contains summed token numbers, such that the entries can be stacked.
# Plot a stacked bar plot
b <- barplot(mat$values,col=qd.colors)
# Add figure names (if needed/wanted)
text(x=b,y=t(mat$cs+(mat$values/2)),
labels=t(substr(mat$labels,0,20)))
Since many of these labels are barely readable, we can restrict the
number of displayed labels to, say, the top 5 figures (i.e., the five
figures that speak the most). We do this by selecting only the top 5
rows in the matrices, using the function head().
# Plot a stacked bar plot
b <- barplot(mat$values,col=qd.colors)
top <- 5
# Add figure names (if needed/wanted)
text(x=b, y=t(head(mat$cs,top)+(head(mat$values,top)/2)),
labels=t(substr(head(mat$labels,top),0,20)))
We will now combine this information with additional meta data about characters, i.e., gender.
# we first create a single table containing data from both plays
characterdata <- rbind(rksp.0$char, rjmw.0$char)
# Proportion of male / female characters
barplot(table(characterdata$Gender),col=qd.colors)
So far, we have counted words. Now we will turn to utterances, and their properties.
First, we will use the function utteranceStatistics() to extract
numbers about utterances
ustat <- utteranceStatistics(rksp.0$mtext,
numberOfFigures = 10, # include 10 figures per drama
normalizeByDramaLength = FALSE # use absolute values
)
colnames(ustat)## [1] "corpus" "drama" "figure" "begin"
## [5] "utteranceLength"
This creates a table with a single row for each utterance. We can now inspect the variance in utterance length
par(mar=c(10,2,2,2))
boxplot(utteranceLength ~ figure, # what do we want to correlate
data=ustat,
las = 3 # rotate axis labels
)
Next, we want to make the same analysis not for individual characters, but for character groups, based on categories such as gender.
ustat <- utteranceStatistics(rksp.0$mtext,
numberOfFigures = 10, # include 10 figures per drama
normalizeByDramaLength = FALSE # use absolute values
)
characterdata <- rksp.0$char
ustat <- merge(ustat, characterdata,
by.x = c("corpus","drama", "figure"),
by.y = c("corpus","drama", "figure_surface"))
par(mar=c(2,2,2,2))
boxplot(utteranceLength ~ Gender, # what do we want to correlate
data=ustat,
las = 1 # rotate axis labels
)
According to this picture, female characters speak slightly longer utterances in this play.
While the above displays the length of utterances, we can also display the position of utterances, i.e., where in the text are they taking place?
par(mar=c(2,10,2,2))
stripchart(begin ~ figure, data=ustat,
las=1, # horizontal labels
pch=20, # use a small bullet as symbol
col=qd.colors # get nice colors
)
Each dot in this plot represents one utterance, the x-axis is measured in character positions. This is not really intuitive, but the flow from left to right represents the flow of the text.
Now it would be useful to include information on act/scene boundaries in
this plot. This can be done by accessing the segmented text table. The
first commands work just as before, with the exception of being applied
to the variable rksp.0.mtext.
ustat <- utteranceStatistics(rksp.0$mtext,
numberOfFigures = 10, # include 10 figures per drama
normalizeByDramaLength = FALSE # use absolute values
)
par(mar=c(2,10,2,2))
stripchart(begin ~ figure, data=ustat,
las=1, # horizontal labels
pch=20, # use a small bullet as symbol
col=qd.colors, # get nice colors
xaxt="n" # suppress the x axis
)
# add vertical lines for act beginning
abline(v=unique(rksp.0$mtext$begin.Act)[-1])
Please note that the information contained in this plot is very similar to the information in the visual and relative configuration matrices.
When characters are speaking on stage, they are actively present. But
they can also be passively present, if other characters refer to them.
Both levels of presence can be extracted with the presence() function:
pres <- presence(rksp.0$mtext)
pres## corpus drama figure scenes actives passives presence
## 1: test rksp.0 angelo 43 2 1 0.02325581
## 2: test rksp.0 appiani 43 5 9 -0.09302326
## 3: test rksp.0 battista 43 4 2 0.04651163
## 4: test rksp.0 camillo_rota 43 1 1 0.00000000
## 5: test rksp.0 claudia_galotti 43 13 1 0.27906977
## 6: test rksp.0 conti 43 2 1 0.02325581
## 7: test rksp.0 der_kammerdiener 43 2 0 0.04651163
## 8: test rksp.0 der_prinz 43 17 13 0.09302326
## 9: test rksp.0 emilia 43 7 16 -0.20930233
## 10: test rksp.0 marinelli 43 19 5 0.32558140
## 11: test rksp.0 odoardo_galotti 43 12 0 0.27906977
## 12: test rksp.0 orsina 43 6 4 0.04651163
## 13: test rksp.0 pirro 43 4 1 0.06976744
As we can see, each character has a few numbers associated: The column
actives shows the number of scenes in which the character is actively
present. This is equivalent to the information in the configuration
matrix. The column passives shows the number of scenes in which a
character is mentioned. By default, this excludes the scenes in which
they are present themselves (this behaviour can be changed by adding the
parameter passiveOnlyWhenNotActive = TRUE to the call of the
presence function).
A simple visualisation that shows the characters active and passive
presence in one plot can be generated like this: The first line
(plot()) is responsible for the plotting of the symbols, the second
line (text()) adds the character names or ids numbers.
plot(x=pres$active/pres$scenes,
y=pres$passive/pres$scenes,
xlim=c(0,1),
ylim=c(0,1),
xlab="Active",
ylab="Passive",
main="Character Presence")
text(x=pres$active/pres$scenes,
y=pres$passive/pres$scenes,
labels=substr(pres$figure,0,20),
pos=3)