1.2.3-SNAPSHOT Arrow_down_16x16

add-lines

incanter.charts

  • (add-lines chart x y & options)
Plots lines on the given scatter or line plot of the (x,y) points.
Equivalent to R's lines function, returns the modified chart object.

Options:
:series-label (default x expression)

Examples:

(use '(incanter core stats io datasets charts))
(def cars (to-matrix (get-dataset :cars)))
(def y (sel cars :cols 0))
(def x (sel cars :cols 1))
(def plot1 (scatter-plot x y :legend true))
(view plot1)

;; add regression line to scatter plot
(def lm1 (linear-model y x))
(add-lines plot1 x (:fitted lm1))

;; model the data without an intercept
(def lm2 (linear-model y x :intercept false))
(add-lines plot1 x (:fitted lm2))


;; Clojure's doto macro can be used to build a chart
(doto (histogram (sample-normal 1000) :density true)
(add-lines (range -3 3 0.05) (pdf-normal (range -3 3 0.05)))
view)


(with-data (get-dataset :iris)
(doto (xy-plot :Sepal.Width :Sepal.Length :legend true)
(add-lines :Petal.Width :Petal.Length)
view))



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:528 top

(defmacro add-lines
" Plots lines on the given scatter or line plot of the (x,y) points.
  Equivalent to R's lines function, returns the modified chart object.

  Options:
    :series-label (default x expression)

  Examples:

    (use '(incanter core stats io datasets charts))
    (def cars (to-matrix (get-dataset :cars)))
    (def y (sel cars :cols 0))
    (def x (sel cars :cols 1))
    (def plot1 (scatter-plot x y :legend true))
    (view plot1)

    ;; add regression line to scatter plot
    (def lm1 (linear-model y x))
    (add-lines plot1 x (:fitted lm1))

    ;; model the data without an intercept
    (def lm2 (linear-model y x :intercept false))
    (add-lines plot1 x (:fitted lm2))


    ;; Clojure's doto macro can be used to build a chart
    (doto (histogram (sample-normal 1000) :density true)
          (add-lines (range -3 3 0.05) (pdf-normal (range -3 3 0.05)))
          view)


    (with-data (get-dataset :iris)
        (doto (xy-plot :Sepal.Width :Sepal.Length :legend true)
              (add-lines :Petal.Width :Petal.Length)
              view))



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


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

Comments top

No comments for add-lines. Log in to add a comment.