Fix plot example in corpusQuery documentation

Change-Id: Ie698bffac7c6220436512c20679807097070aa63
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
index b37932d..723ef3e 100644
--- a/R/KorAPQuery.R
+++ b/R/KorAPQuery.R
@@ -111,14 +111,15 @@
 #' kqo
 #'
 #' # Plot the time/frequency curve of "Ameisenplage"
-#' kco <- new("KorAPConnection")
-#' q <- corpusQuery(kco, "Ameisenplage")
-#' q <- fetchAll(q, verbose=TRUE)
-#' tokensPerYear <- function(year) { return(corpusStats(kco, paste("pubDate in", year))@tokens) }
+#' kco <- new("KorAPConnection", verbose=TRUE)
+#' q <- fetchAll(corpusQuery(kco, "Ameisenplage"))
 #' df <- as.data.frame(table(as.numeric(format(q@collectedMatches$pubDate,"%Y")), dnn="year"),
 #'                     stringsAsFactors = FALSE)
-#' df$ipm <- 1000000 * df$Freq / tokensPerYear(df$year)
-#' plot(df$year, df$ipm, type="l")
+#' df$Freq <- mapply(function(f, y) f / corpusStats(kco, paste("pubDate in", y))@tokens,
+#'                   df$Freq, df$year)
+#' df <- merge(data.frame(year=min(df$year):max(df$year)), df, all = TRUE)
+#' df[is.na(df$Freq),]$Freq <- 0
+#' plot(df, type="l")
 #'
 #' @seealso \code{\link{KorAPConnection}}, \code{\link{fetchNext}}, \code{\link{fetchRest}}, \code{\link{fetchAll}}, \code{\link{corpusStats}}
 #'
diff --git a/man/corpusQuery-KorAPConnection-method.Rd b/man/corpusQuery-KorAPConnection-method.Rd
index 759fd62..86d98e5 100644
--- a/man/corpusQuery-KorAPConnection-method.Rd
+++ b/man/corpusQuery-KorAPConnection-method.Rd
@@ -52,14 +52,15 @@
 kqo
 
 # Plot the time/frequency curve of "Ameisenplage"
-kco <- new("KorAPConnection")
-q <- corpusQuery(kco, "Ameisenplage")
-q <- fetchAll(q, verbose=TRUE)
-tokensPerYear <- function(year) { return(corpusStats(kco, paste("pubDate in", year))@tokens) }
+kco <- new("KorAPConnection", verbose=TRUE)
+q <- fetchAll(corpusQuery(kco, "Ameisenplage"))
 df <- as.data.frame(table(as.numeric(format(q@collectedMatches$pubDate,"\%Y")), dnn="year"),
                     stringsAsFactors = FALSE)
-df$ipm <- 1000000 * df$Freq / tokensPerYear(df$year)
-plot(df$year, df$ipm, type="l")
+df$Freq <- mapply(function(f, y) f / corpusStats(kco, paste("pubDate in", y))@tokens,
+                  df$Freq, df$year)
+df <- merge(data.frame(year=min(df$year):max(df$year)), df, all = TRUE)
+df[is.na(df$Freq),]$Freq <- 0
+plot(df, type="l")
 
 }
 \references{