blob: d8ea3b7e54e26738e4ae6076fd6c5de2d710740a [file] [log] [blame]
Marc Kupietz83aee032019-11-22 18:45:25 +01001#!/usr/bin/env Rscript
2#
3# Visualize frequencies of alternative query terms in relation to other variables
4# specified in virtual corpus definitions.
5#
6library(RKorAPClient)
7library(vcd)
8library(tibble)
9library(dplyr)
Marc Kupietz83aee032019-11-22 18:45:25 +010010
11mosaicplot <- function(query, vc, kco = new("KorAPConnection", verbose = TRUE)) {
12 frequencyQuery(
13 query = query,
14 vc = vc,
15 kco,
16 expand = TRUE,
17 as.alternatives = TRUE
18 ) %>%
19 mutate(alternative = queryStringToLabel(query), condition = queryStringToLabel(vc)) %>%
20 { . ->> queryResult } %>%
21 { xtabs(totalResults ~ condition + alternative, .)} %>%
22 vcd::mosaic(shade = TRUE) # , labeling = labeling_border(rot_labels = c(45,0,0,0), just_labels = c("left", "center", "center", "right")))
Marc Kupietz0cdb7092023-07-29 11:49:15 +020023 queryResult
Marc Kupietz83aee032019-11-22 18:45:25 +010024}
25queryResult <- mosaicplot(c("[marmot/m=mood:subj]", "[marmot/m=mood:ind]"), c("textDomain=Wirtschaft", "textDomain=Kultur", "textDomain=Sport"))
26#mosaicplot(c("Asylbewerber", "Asylwerber"), c("pubPlaceKey=DE", "pubPlaceKey=AT"))
27#mosaicplot(c("wegen dem [tt/p=NN]", "wegen des [tt/p=NN]"), c("pubPlaceKey=DE", "pubPlaceKey=AT"))
28#mosaicplot(c("Samstag", "Sonnabend"), c("pubPlace=Hamburg", "pubPlace=Berlin"))
29#mosaicplot(c("Tomaten", "Paradeiser"), c("pubPlaceKey=DE", "pubPlaceKey=AT"))
30#mosaicplot(c("Samstag", "Sonnabend"), c("pubPlace=Hamburg", "pubPlace=Berlin", 'pubPlaceKey=AT'))
31