blob: b23d2bfc67bea58c0f01f015192bdb46664a93cf [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 Kupietz865760f2019-10-07 19:29:44 +02009library(plotly)
Marc Kupietz9d57d4b2019-09-25 20:02:37 +020010
11conditionsOverTime <- function(query, conditions, years, kco = new("KorAPConnection", verbose = TRUE)) {
Marc Kupietz296e4932019-10-04 22:51:11 +020012 g <- expand_grid(condition = conditions, year = years) %>%
Marc Kupietz0de631d2019-10-07 10:10:18 +020013 cbind(frequencyQuery(kco, query, sprintf("%s & pubDate in %d", .$condition, .$year))) %>%
14 ipm() %>%
Marc Kupietz865760f2019-10-07 19:29:44 +020015 ggplot(aes(x = year, y = ipm, fill=condition, color=condition)) +
Marc Kupietz0de631d2019-10-07 10:10:18 +020016 geom_freq_by_year_ci() +
Marc Kupietz9d57d4b2019-09-25 20:02:37 +020017 xlab("TIME") +
18 labs(color="Virtual Corpus", fill="Virtual Corpus") +
Marc Kupietz0de631d2019-10-07 10:10:18 +020019 ylab(sprintf("Observed frequency/million of \u201c%s\u201d", query))
Marc Kupietz865760f2019-10-07 19:29:44 +020020 p <- RKorAPClient::ggplotly(g)
21 print(p)
Marc Kupietz9d57d4b2019-09-25 20:02:37 +020022}
Marc Kupietz296e4932019-10-04 22:51:11 +020023
24conditionsOverTime("[tt/l=Heuschrecke]", c("textClass = /natur.*/", "textClass=/politik.*/", "textClass=/wirtschaft.*/"), (2002:2018))