Marc Kupietz | 83aee03 | 2019-11-22 18:45:25 +0100 | [diff] [blame] | 1 | #!/usr/bin/env Rscript |
| 2 | # |
| 3 | # Visualize frequencies of alternative query terms in relation to other variables |
| 4 | # specified in virtual corpus definitions. |
| 5 | # |
| 6 | library(RKorAPClient) |
| 7 | library(vcd) |
| 8 | library(tibble) |
| 9 | library(dplyr) |
Marc Kupietz | 83aee03 | 2019-11-22 18:45:25 +0100 | [diff] [blame] | 10 | |
| 11 | mosaicplot <- 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 Kupietz | 0cdb709 | 2023-07-29 11:49:15 +0200 | [diff] [blame] | 23 | queryResult |
Marc Kupietz | 83aee03 | 2019-11-22 18:45:25 +0100 | [diff] [blame] | 24 | } |
| 25 | queryResult <- 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 | |