Use the convenience functions in the demos
Change-Id: I6dd571d92c523e43fecf1f0d183f527da445a7a2
diff --git a/demo/alternativesOverTime.R b/demo/alternativesOverTime.R
index 00306cd..ae91ff5 100755
--- a/demo/alternativesOverTime.R
+++ b/demo/alternativesOverTime.R
@@ -12,14 +12,11 @@
cbind(corpusQuery(kco, .$Variant, sprintf("textType = /Zeit.*/ & pubDate in %d", .$year))) %>%
group_by(year) %>% mutate(tokens = sum(totalResults)) %>%
ci()
- g <- ggplot(data = df, mapping = aes(x = year, y = f, color = Variant, fill = Variant)) +
- geom_ribbon(aes(ymin = conf.low, ymax = conf.high, color = Variant, fill = Variant), alpha = .3, linetype = 0) +
- geom_line() +
- geom_point() +
+ g <- ggplot(data = df, mapping = aes(x = year, y = f, color = Variant, fill = Variant, ymin = conf.low, ymax = conf.high)) +
+ geom_freq_by_year_ci() +
ggtitle(paste0(alternatives, collapse = " vs. ")) +
xlab("TIME") +
- ylab(sprintf("Observed frequency ratio")) +
- theme(axis.text.x = element_text(angle = 45, hjust = 1)) + scale_x_continuous(breaks = unique(df$year))
+ ylab(sprintf("Observed frequency ratio"))
pp <- ggplotly(g, tooltip = c("x", "y"))
for (i in 1:length(alternatives)) {
vdata <- df[df$Variant == alternatives[i],]
diff --git a/demo/conditionsOverTime.R b/demo/conditionsOverTime.R
index 3f85f8e..9f0590d 100644
--- a/demo/conditionsOverTime.R
+++ b/demo/conditionsOverTime.R
@@ -6,23 +6,17 @@
#install_git("https://korap.ids-mannheim.de/gerrit/KorAP/RKorAPClient", upgrade="never")
library(RKorAPClient)
library(ggplot2)
-library(reshape2)
-#library(plotly)
conditionsOverTime <- function(query, conditions, years, kco = new("KorAPConnection", verbose = TRUE)) {
g <- expand_grid(condition = conditions, year = years) %>%
- cbind(frequencyQuery(kco, query, sprintf("%s & pubDate in %d", .$condition, .$year))) %>%
- ggplot(aes(x = year, y = f, fill=condition, color=condition)) +
- geom_point() +
- geom_line() +
- geom_ribbon(aes(ymin=conf.low, ymax=conf.high, fill=condition, color=condition), alpha=.3, linetype=0) +
+ cbind(frequencyQuery(kco, query, sprintf("%s & pubDate in %d", .$condition, .$year))) %>%
+ ipm() %>%
+ ggplot(aes(x = year, y = ipm, fill=condition, color=condition, ymin=conf.low, ymax=conf.high)) +
+ geom_freq_by_year_ci() +
xlab("TIME") +
labs(color="Virtual Corpus", fill="Virtual Corpus") +
- ylab(sprintf("Observed frequency of \u201c%s\u201d", query)) +
- theme(axis.text.x = element_text(angle = 45, hjust = 1)) + scale_x_continuous(breaks=unique(df$year))
+ ylab(sprintf("Observed frequency/million of \u201c%s\u201d", query))
print(g)
- # print(ggplotly(g, tooltip = c("x", "y")))
}
-#df <- conditionsOverTime("wegen dem [tt/p=NN]", c("textClass = /sport.*/", "textClass=/politik.*/", "textClass=/kultur.*/"), (1995:2005))
conditionsOverTime("[tt/l=Heuschrecke]", c("textClass = /natur.*/", "textClass=/politik.*/", "textClass=/wirtschaft.*/"), (2002:2018))