Files
nlnieuws/r/test-rang.R
Peter Kleiweg 01e6d48665 stijgers
2026-06-18 12:52:40 +02:00

33 lines
1.1 KiB
R

nw <- read.table('data/2026/algemeen-rang-per-2026.23-1', sep="\t", quote="", encoding="utf-8", col.names=c("f", "word"))
od <- read.table('data/2026/algemeen-rang-per-2026.22-4', sep="\t", quote="", encoding="utf-8", col.names=c("f", "word"))
words <- unique(c(od$word, nw$word))
o <- order(words)
words <- words[o]
n <- length(words)
d <- data.frame(word=words, od=rep(NA, n), nw=rep(NA, n))
for (word in nw$word) {
d$nw[d$word==word] <- nw$f[nw$word==word]
}
for (word in od$word) {
d$od[d$word==word] <- od$f[od$word==word]
}
d$nw[is.na(d$nw)] <- max(nw$f) + 2
d$od[is.na(d$od)] <- max(od$f) + 2
myplot <- function(values, labels, titel="", sub ="") {
y <- 1:length(values)
xx <- range(values)
plot(values, y, xlim=c(xx[1], xx[2] + (xx[2]-xx[1]) / 5), xlab="score", ylab="index", main=titel, sub=sub)
text(values, y, labels, pos=4)
}
nwn <- (d$nw - 1) / (max(nw$f) + 1)
odn <- (d$od - 1) / (max(od$f) + 1)
v <- odn - nwn
o <- order(-v)
myplot(v[o][1:40], words[o][1:40], titel="score op basis van genormaliseerde rang", "week 23 t.o.v. week 19 t/m 22")