1

I want to align my x-axis labels in Incanter's histogram (based on JFreeChart) so that they are centered under the bars. I also want to get rid of the fractional axis tick marks.

My question is very similar to JFreeChart: Aligning domain axis with histogram bins.

Here are related questions for other languages:

(require '[incanter.charts :refer [histogram]])
(require '[incanter.core :refer [view]])
(def data [1 1 1 1 3 6])
(view (histogram data))

Incanter Example Histogram

P.S. The histogram is also unappealing in that the bar for 6 is to the left of the tick mark. The other bars are to the right of their tick marks!

Update: See also:

Community
  • 1
  • 1
David J.
  • 31,569
  • 22
  • 122
  • 174

1 Answers1

1

Based on reviewing the Incanter source code and the JFreeChart documentation, I don't believe that org.jfree.chart.ChartFactory/createHistogram exposes the functionality to customize the axis. (I could be wrong -- perhaps you can modify the axis after using that factory method.)

In any case, I found it easier (and perhaps necessary) to use the bar-chart directly:

(ns custom-incanter
  (:require
   [incanter.charts :as ic]
   [incanter.core :as i]))

(defn hist
  [values title]
  {:pre [(sequential? values)]}
  (let [freq (frequencies values)
        f #(freq % 0)
        ks (keys freq)
        a (apply min ks)
        b (apply max ks)
        x-values (range a (inc b))
        x-labels (map str x-values)
        y-values (map f x-values)]
    (i/view (ic/bar-chart x-labels y-values :title title))))

Use it like this:

(hist [1 1 1 1 3 6] "Using Bar Chart")

Custom Histogram Using Bar Chart

David J.
  • 31,569
  • 22
  • 122
  • 174