Learn R Programming

sumer (version 1.3.0)

plot_sign_grammar: Stacked Bar Chart of Grammatical Type Frequencies

Description

Creates a stacked bar chart from the output of sign_grammar or grammar_probs. Each bar represents one sign position in the sentence. The colours indicate the relative frequency or posterior probability of each individual grammatical type.

Usage

plot_sign_grammar(sg,
                  output_file = NULL,
                  width       = 10,
                  height      = 5,
                  sign_names  = FALSE,
                  font_family = NULL,
                  mapping     = NULL)

Value

Invisibly returns the ggplot2 plot object.

Arguments

sg

A data frame as returned by sign_grammar (with column n) or grammar_probs (with column prob).

output_file

Character. File path for saving the plot (PNG or JPG). If NULL (default), the plot is displayed on the current device.

width

Numeric. Plot width in inches. Default: 10.

height

Numeric. Plot height in inches. Default: 5.

sign_names

Logical. Whether sign names or cuneiform characters should be used as labels of the x-axis. Default: FALSE.

font_family

Character. Font family for cuneiform x-axis labels. If NULL (default), a cuneiform-capable font is detected automatically.

mapping

A data frame containing the sign mapping table with columns syllables, name, and cuneiform. If NULL (the default), the package's internal mapping file etcsl_mapping.txt is loaded.

Details

When the input comes from sign_grammar() (column n), absolute frequencies are converted to percentages so that bars sum to 100%. When the input comes from grammar_probs() (column prob), posterior probabilities are used directly.

Colours are assigned per grammatical type, grouped by class:

  • Red shades: Verbs (V) and operators returning verbs

  • Blue shades: Operators returning attributes A

  • Orange: Adjectives and other signs with grammatical type (Sx->S)

  • Green: Nouns

  • Grey/other shades: All other types

See Also

sign_grammar for generating raw frequency data, grammar_probs for Bayesian posterior probabilities, prior_probs for computing the prior.

Examples

Run this code
dic   <- read_dictionary()
sg    <- sign_grammar("a-ma-ru ba-ur3 ra", dic)

# Plot raw frequencies
file <- file.path(tempdir(), "test.png")
plot_sign_grammar(sg, file)

# Plot probabilities
prior <- prior_probs(dic, sentence_prob = 0.25)
gp    <- grammar_probs(sg, prior, dic, alpha0 = 1)
file  <- file.path(tempdir(), "test2.png")
plot_sign_grammar(gp, file)

Run the code above in your browser using DataLab