1.2.3-SNAPSHOT Arrow_down_16x16

add-points

incanter.charts

  • (add-points chart x y & options)
Plots points on the given scatter-plot or xy-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))

;; add regression line to scatter plot
(def lm1 (linear-model y x))
;; model the data without an intercept
(def lm2 (linear-model y x :intercept false))

(doto (xy-plot x (:fitted lm1) :legend true)
view
(add-points x y)
(add-lines x (:fitted lm2)))


(with-data (get-dataset :iris)
(doto (scatter-plot :Sepal.Length :Sepal.Width :data ($where {:Species "setosa"}))
(add-points :Sepal.Length :Sepal.Width :data ($where {:Species "versicolor"}))
(add-points :Sepal.Length :Sepal.Width :data ($where {:Species "virginica"}))
view))

;; of course this chart can be achieved in a single line:
(view (scatter-plot :Sepal.Length :Sepal.Width :group-by :Species :data (get-dataset :iris)))



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

(defmacro add-points
" Plots points on the given scatter-plot or xy-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))

    ;; add regression line to scatter plot
    (def lm1 (linear-model y x))
    ;; model the data without an intercept
    (def lm2 (linear-model y x :intercept false))

    (doto (xy-plot x (:fitted lm1) :legend true)
          view
          (add-points x y)
          (add-lines x (:fitted lm2)))


    (with-data (get-dataset :iris)
      (doto (scatter-plot :Sepal.Length :Sepal.Width :data ($where {:Species \"setosa\"}))
            (add-points :Sepal.Length :Sepal.Width :data ($where {:Species \"versicolor\"}))
            (add-points :Sepal.Length :Sepal.Width :data ($where {:Species \"virginica\"}))
            view))

    ;; of course this chart can be achieved in a single line:
    (view (scatter-plot :Sepal.Length :Sepal.Width :group-by :Species :data (get-dataset :iris)))



  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-points* args#))))
Vars in incanter.charts/add-points: apply assoc defmacro when concat format let list or seq vector
Used in 0 other vars

Comments top

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