I'm not sure what you want, but as far as I got you, it's something like this:
(use '(incanter core charts interpolation))
(defn my-plot [[data [[cx cy]]]]
(let [x (map first data)
y (map second data)
lbound (apply min x)
rbound (apply max x)
interp (interpolate data :cubic-hermite)]
(-> (function-plot interp lbound rbound)
(add-points x y)
(add-points [cx] [cy])
view)))
I'm using :cubic-hermite
spline interpolation to make the line smooth, and I'm using add-points
function to add data points to the plot.
You'll find more interpolation examples here.
But three points isn't enough for good interpolation, so you should consider using linear interpolation instead:
(defn my-plot [[data [[cx cy]]]]
(let [x (map first data)
y (map second data)]
(-> (xy-plot x y)
(add-points x y)
(add-points [cx] [cy])
view)))
Update:
Let's have a closer look at what I'm doing here.
First, I'm using destructuring to extract data points and cluster coordinates (I'm assuming that you always have a single cluster following your data points):
(defn my-plot [[data [[cx cy]]]]
Then I'm breaking nested vector of [x y]
pairs into two vectors (one for each dimension):
(let [x (map first data)
y (map second data)]
Then I'm creating a plot object and drawing a line on it using your data points:
(-> (xy-plot x y)
Then I'm adding original data point (blue dots):
(add-points x y)
and your cluster (green dot):
(add-points [cx] [cy])
Finally, I'm displaying resulting plot:
view)))
In my first example I'm also using interpolation to make the line smoother:
lbound (apply min x)
rbound (apply max x)
interp (interpolate data :cubic-hermite)]
(-> (function-plot interp lbound rbound)
I'm using function-plot
here because interp
object is a function.