1.2.3-SNAPSHOT permalink Arrow_down_16x16

line-chart

incanter.charts

  • (line-chart categories values & options)
Returns a JFreeChart object representing a line-chart of the given values and categories.
Use the 'view' function to display the chart, or the 'save' function
to write it to a file.

Arguments:
categories -- a sequence of categories
values -- a sequence of numeric values

Options:
:title (default 'Histogram') main title
:x-label (default 'Categories')
:y-label (default 'Value')
:legend (default false) prints legend
:series-label
:group-by (default nil) -- a vector of values used to group the values into
series within each category.
:gradient? (default false) -- use gradient on bars


See also:
view and save

Examples:

(use '(incanter core stats charts datasets))

(def data (get-dataset :airline-passengers))
(def years (sel data :cols 0))
(def months (sel data :cols 2))
(def passengers (sel data :cols 1))
(view (line-chart years passengers :group-by months :legend true))
(view (line-chart months passengers :group-by years :legend true))


(def seasons (mapcat identity (repeat 3 ["winter" "spring" "summer" "fall"])))
(def years (mapcat identity (repeat 4 [2007 2008 2009])))
(def x (sample-uniform 12 :integers true :max 100))
(view (line-chart years x :group-by seasons :legend true))

(view (line-chart ["a" "b" "c" "d" "e" "f"] [10 20 30 10 40 20]))

(view (line-chart (sample "abcdefghij" :size 10 :replacement true)
(sample-uniform 10 :max 50) :legend true))

;; add a series label
(def plot (line-chart ["a" "b" "c"] [10 20 30] :legend true :series-label "s1"))
(view plot)
(add-categories plot ["a" "b" "c"] [5 25 40] :series-label "s2")


(view (line-chart :year :passengers :group-by :month :legend true :data data))

(view (line-chart :month :passengers :group-by :year :legend true :data data))

(with-data data
(view (line-chart :month :passengers :group-by :year :legend true)))

(with-data (->> ($rollup :sum :passengers :year (get-dataset :airline-passengers))
($order :year :asc))
(view (line-chart :year :passengers)))

(with-data (->> ($rollup :sum :passengers :month (get-dataset :airline-passengers))
($order :passengers :asc))
(view (line-chart :month :passengers)))


(with-data ($rollup :sum :passengers :month (get-dataset :airline-passengers))
(view (line-chart :month :passengers)))



References:
http://www.jfree.org/jfreechart/api/javadoc/
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/JFreeChart.html

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source incanter/charts.clj:1344 top

(defmacro line-chart
" Returns a JFreeChart object representing a line-chart of the given values and categories.
  Use the 'view' function to display the chart, or the 'save' function
  to write it to a file.

  Arguments:
    categories -- a sequence of categories
    values -- a sequence of numeric values

  Options:
    :title (default 'Histogram') main title
    :x-label (default 'Categories')
    :y-label (default 'Value')
    :legend (default false) prints legend
    :series-label
    :group-by (default nil) -- a vector of values used to group the values into
                               series within each category.
    :gradient? (default false) -- use gradient on bars


  See also:
    view and save

  Examples:

    (use '(incanter core stats charts datasets))

    (def data (get-dataset :airline-passengers))
    (def years (sel data :cols 0))
    (def months (sel data :cols 2))
    (def passengers (sel data :cols 1))
    (view (line-chart years passengers :group-by months :legend true))
    (view (line-chart months passengers :group-by years :legend true))


    (def seasons (mapcat identity (repeat 3 [\"winter\" \"spring\" \"summer\" \"fall\"])))
    (def years (mapcat identity (repeat 4 [2007 2008 2009])))
    (def x (sample-uniform 12 :integers true :max 100))
    (view (line-chart years x :group-by seasons :legend true))

    (view (line-chart [\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"] [10 20 30 10 40 20]))

    (view (line-chart (sample \"abcdefghij\" :size 10 :replacement true)
                         (sample-uniform 10 :max 50) :legend true))

    ;; add a series label
    (def plot (line-chart [\"a\" \"b\" \"c\"] [10 20 30] :legend true :series-label \"s1\"))
    (view plot) 
    (add-categories plot [\"a\" \"b\" \"c\"] [5 25 40] :series-label \"s2\")  
 

    (view (line-chart :year :passengers :group-by :month :legend true :data data)) 
    
    (view (line-chart :month :passengers :group-by :year :legend true :data data))
    
    (with-data data
      (view (line-chart :month :passengers :group-by :year :legend true)))

    (with-data (->> ($rollup :sum :passengers :year (get-dataset :airline-passengers))
                    ($order :year :asc))
      (view (line-chart :year :passengers)))

    (with-data (->> ($rollup :sum :passengers :month (get-dataset :airline-passengers))
                    ($order :passengers :asc))
      (view (line-chart :month :passengers)))


    (with-data ($rollup :sum :passengers :month (get-dataset :airline-passengers))
      (view (line-chart :month :passengers)))



  References:
    http://www.jfree.org/jfreechart/api/javadoc/
    http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/JFreeChart.html

"
  ([categories values & options]
    `(let [opts# ~(when options (apply assoc {} options))
           group-by# (:group-by opts#) 
           main-title# (or (:title opts#) "")
           x-lab# (or (:x-label opts#) (str '~categories))
           y-lab# (or (:y-label opts#) (str '~values))
           series-lab# (or (:series-label opts#) (if group-by#
						   (format "%s, %s (0)" '~categories '~values) 
						   (format "%s, %s" '~categories '~values)))
	   args# (concat [~categories ~values] (apply concat (seq (apply assoc opts# 
							   [:group-by group-by# 
							    :main-title main-title# 
							    :x-label x-lab# 
							    :y-label y-lab# 
							    :series-label series-lab#]))))]
        (apply line-chart* args#))))
Vars in incanter.charts/line-chart: apply assoc defmacro when concat format let list or seq str vector
Used in 0 other vars

Comments top

No comments for line-chart. Log in to add a comment.