func RTHistogram(title string, data map[string][]int, dodge bool, filename string) error {
	file, err := os.Create(filename + ".R")
	if err != nil {
		return err
	}
	defer file.Close()
	fmt.Fprintf(file, "library(ggplot2)\n")
	min, max, fewest, most := 9999999999, -9999999999, 9999999999, 0
	for _, rt := range data {
		if len(rt) < fewest {
			fewest = len(rt)
		} else if len(rt) > most {
			most = len(rt)
		}
		for _, n := range rt {
			if n < 0 {
				continue
			}
			if n < min {
				min = n
			} else if n > max {
				max = n
			}
		}
	}
	binwidth := optimumBinBiwdth(min, max, fewest, most)
	fmt.Fprintf(file, "ResponseTime <- c(")
	label := ""
	first := true
	for row, rt := range data {
		if label == "" {
			label += fmt.Sprintf(`Label <- c(rep("%s", times=%d)`, row, len(rt))
		} else {
			label += fmt.Sprintf(`, rep("%s", times=%d)`, row, len(rt))
		}
		for _, n := range rt {
			if first {
				fmt.Fprintf(file, "%d", n)
				first = false
			} else {
				fmt.Fprintf(file, ", %d", n)
			}
		}
		fmt.Fprintf(file, "\n")
	}
	fmt.Fprintf(file, ")\n")
	label += ")"
	fmt.Fprintf(file, "%s\n", label)
	fmt.Fprintf(file, "rt.data <- data.frame(Label, ResponseTime)\n")
	fmt.Fprintf(file, "p <- ggplot(rt.data, aes(x=ResponseTime, fill=Label))\n")
	fmt.Fprintf(file, "png(%q)\n", filename)
	pos := ""
	if dodge {
		pos = `, position="dodge"`
	}
	fmt.Fprintf(file, "print(p + geom_histogram(binwidth=%d%s) + ggtitle(%q))\n",
		binwidth, pos, title)
	fmt.Fprintf(file, "dev.off()\n")
	file.Close()
	args := []string{filename + ".R"}
	cmd := exec.Command(rScriptPath, args...)
	err = cmd.Run()
	return err
}
RTHistogram produces a png file containing a histogram of the int values in
data. Several histograms can be plotted, the keys of data are the labels.
If dodge is true the histogram bars are not stacked.
package ht
import (
	"fmt"
	"os"
	"os/exec"
)