blob: 9f0590d70b970a7d7f619725644a4391d1a155fc [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() %>%
14 ggplot(aes(x = year, y = ipm, fill=condition, color=condition, ymin=conf.low, ymax=conf.high)) +
15 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 Kupietz9d57d4b2019-09-25 20:02:37 +020019 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))