blob: ccd5592e94bb88d0310d8c8d30d9a764305821b6 [file] [log] [blame]
Marc Kupietz9d57d4b2019-09-25 20:02:37 +02001#!/usr/bin/env Rscript
2#
3# Plot frequency of an expressions under multiple conditions over time
4#
5#library(devtools)
6#install_git("https://korap.ids-mannheim.de/gerrit/KorAP/RKorAPClient", upgrade="never")
7library(RKorAPClient)
8library(ggplot2)
Marc Kupietz9d57d4b2019-09-25 20:02:37 +02009
10conditionsOverTime <- function(query, conditions, years, kco = new("KorAPConnection", verbose = TRUE)) {
Marc Kupietz296e4932019-10-04 22:51:11 +020011 g <- expand_grid(condition = conditions, year = years) %>%
Marc Kupietz0de631d2019-10-07 10:10:18 +020012 cbind(frequencyQuery(kco, query, sprintf("%s & pubDate in %d", .$condition, .$year))) %>%
13 ipm() %>%
Marc Kupietz865760f2019-10-07 19:29:44 +020014 ggplot(aes(x = year, y = ipm, fill=condition, color=condition)) +
Marc Kupietz0de631d2019-10-07 10:10:18 +020015 geom_freq_by_year_ci() +
Marc Kupietz9d57d4b2019-09-25 20:02:37 +020016 xlab("TIME") +
17 labs(color="Virtual Corpus", fill="Virtual Corpus") +
Marc Kupietz0de631d2019-10-07 10:10:18 +020018 ylab(sprintf("Observed frequency/million of \u201c%s\u201d", query))
Marc Kupietz5fb892e2021-03-05 08:18:25 +010019 print(g)
Marc Kupietz9d57d4b2019-09-25 20:02:37 +020020}
Marc Kupietz296e4932019-10-04 22:51:11 +020021
22conditionsOverTime("[tt/l=Heuschrecke]", c("textClass = /natur.*/", "textClass=/politik.*/", "textClass=/wirtschaft.*/"), (2002:2018))