Marc Kupietz | 9d57d4b | 2019-09-25 20:02:37 +0200 | [diff] [blame] | 1 | #!/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") |
| 7 | library(RKorAPClient) |
| 8 | library(ggplot2) |
Marc Kupietz | 9d57d4b | 2019-09-25 20:02:37 +0200 | [diff] [blame] | 9 | |
| 10 | conditionsOverTime <- function(query, conditions, years, kco = new("KorAPConnection", verbose = TRUE)) { |
Marc Kupietz | 296e493 | 2019-10-04 22:51:11 +0200 | [diff] [blame] | 11 | g <- expand_grid(condition = conditions, year = years) %>% |
Marc Kupietz | 0de631d | 2019-10-07 10:10:18 +0200 | [diff] [blame^] | 12 | 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 Kupietz | 9d57d4b | 2019-09-25 20:02:37 +0200 | [diff] [blame] | 16 | xlab("TIME") + |
| 17 | labs(color="Virtual Corpus", fill="Virtual Corpus") + |
Marc Kupietz | 0de631d | 2019-10-07 10:10:18 +0200 | [diff] [blame^] | 18 | ylab(sprintf("Observed frequency/million of \u201c%s\u201d", query)) |
Marc Kupietz | 9d57d4b | 2019-09-25 20:02:37 +0200 | [diff] [blame] | 19 | print(g) |
Marc Kupietz | 9d57d4b | 2019-09-25 20:02:37 +0200 | [diff] [blame] | 20 | } |
Marc Kupietz | 296e493 | 2019-10-04 22:51:11 +0200 | [diff] [blame] | 21 | |
| 22 | conditionsOverTime("[tt/l=Heuschrecke]", c("textClass = /natur.*/", "textClass=/politik.*/", "textClass=/wirtschaft.*/"), (2002:2018)) |