plot_summary_lenghts.R 1.71 KB
require(ggplot2)
require(grid)
require(gridExtra)
require(lattice)

DATA_DIR="../../../../data/"

########################## functions
gpl = function(d) {
    ggplot(d, aes(x=as.factor(d$SumRatio), y=SumRealRatio)) +
    geom_boxplot(outlier.shape=4, outlier.colour = "blue") +
    ylim(0, 40) +
    ylab("Obtained summary ratio (word count)") +
    xlab("Requested summary ratio (word count)") +
    theme(text = element_text(size=15))
}

ploto = function(d) {
    p = gpl(d)
}

histo = function(d) {
    p = ggplot(d, aes(abs(d$SumRealRatio*100/d$SumRatio))) +
    geom_histogram(binwidth = 1) +
    xlim(80, 120) +
    ylab("Number of summaries") +
    xlab("Obtained summary ratio as percent of requested ratio (20%)") +
    theme(text = element_text(size=15))
}

######################### automatic summaries
data = read.csv(paste(DATA_DIR, "summary-lengths.tsv", sep=""), sep = "\t")

names = list("Swietl", "nicolas", "nicolas-zero", "BASELINE")
titles = list("Świetlicka", "Nicolas", "Nicolas-zero", "Baseline")
plots = list()
hists = list()
i = 1
for (n in names) {
    print(n)
    title = titles[[i]]
    i = i + 1

    d = data[data$SumAuthor==n,]
    print(mean(d$SumRealRatio))

    p = ploto(d)
    p = p + ggtitle(title)
    plots = c(plots, list(p))

    hi = histo(d)
    hi = hi + ggtitle(title)
    hists = c(hists, list(hi))
}

pdf(file=paste(DATA_DIR, "summary-length-plots.pdf", sep=""), encoding="ISOLatin2", width=11.69, height=8.27)
grid.arrange(plots[[1]], plots[[2]],  plots[[3]], plots[[4]], ncol=2, nrow=2)
dev.off()

pdf(file=paste(DATA_DIR, "summary-length-hists.pdf", sep=""), encoding="ISOLatin2", width=11.69, height=8.27)
grid.arrange(hists[[1]], hists[[2]],  hists[[3]], hists[[4]], ncol=2, nrow=2)
dev.off()