Adds a polygon outline defined by a given coordinates. The last coordinate will
close with the first. If only two points are given, it will plot a line.
Arguments:
chart -- the chart to add the polygon to.
coords -- a list of coords (an n-by-2 matrix can also be used)
Examples:
(use '(incanter core stats charts))
(def x (range -3 3 0.01))
(def plot (xy-plot x (pdf-normal x)))
(view plot)
;; add polygon to the chart
(add-polygon plot [[-1.96 0] [1.96 0] [1.96 0.4] [-1.96 0.4]])
;; the coordinates can also be passed in a matrix
;; (def points (matrix [[-1.96 0] [1.96 0] [1.96 0.4] [-1.96 0.4]]))
;; (add-polygon plot points)
;; add a text annotation
(add-text plot -1.25 0.35 "95% Conf Interval")
;; PCA chart example
(use '(incanter core stats charts datasets))
;; load the iris dataset
(def iris (to-matrix (get-dataset :iris)))
;; run the pca
(def pca (principal-components (sel iris :cols (range 4))))
;; extract the first two principal components
(def pc1 (sel (:rotation pca) :cols 0))
(def pc2 (sel (:rotation pca) :cols 1))
;; project the first four dimension of the iris data onto the first
;; two principal components
(def x1 (mmult (sel iris :cols (range 4)) pc1))
(def x2 (mmult (sel iris :cols (range 4)) pc2))
;; now plot the transformed data, coloring each species a different color
(def plot (scatter-plot x1 x2
:group-by (sel iris :cols 4)
:x-label "PC1" :y-label "PC2" :title "Iris PCA"))
(view plot)
;; put box around the first group
(add-polygon plot [[-3.2 -6.3] [-2 -6.3] [-2 -3.78] [-3.2 -3.78]])
;; add some text annotations
(add-text plot -2.5 -6.5 "Setosa")
(add-text plot -5 -5.5 "Versicolor")
(add-text plot -8 -5.5 "Virginica")
Comments top
No comments for add-polygon. Log in to add a comment.