To associate beautiful names with a series of dots or lines, use the keyword :series-label in a command that adds this data to the chart. For instance:
(def c (scatter plot xy :legend true)) (add-lines c x1 y1 :series-label "Primary") (add-lines c x2 y2 :series-label "Secondary")
This does not apply to another problem in your question: to create a bare scatter plot that has a legend, you must pass empty data to the scatter-plot , i.e. with x and y as empty sequences, since Incanter does not allow you to specify :legend without transferring data to scatter-plot . If x and y are empty (for example, they are nil ), empty data is also displayed as an element in the legend. I do not believe that this problem can be overcome right now (version 1.5.7).
One solution is to transfer real data in a scatter call, along with the :series-label option. However, this can make it difficult to programmatically create a scatterplot when the number of datasets is not known in advance, since you must process the first dataset differently than others.
Another kludgey solution is the following:
(def chart (scatter-plot nil nil :legend true :series-label "")) (set-stroke-color chart (java.awt.Color. 0 0 0 0) :dataset 0)
Using an empty string as the value :series-label means that the label in the legend for the first, empty dataset will not be displayed. Calling set-stroke-color makes the color of an empty dataset (i.e., Dataset 0) transparent. Otherwise, you will have a red dot for this data set in your legend. You will have a small empty space in the legend where the red dot and the empty line belong, but this is less confusing than seeing the red dot there.
Mars source share