In the last recipe, we customized the type of chart and how the data is displayed and laid out. However, we'll often want to customize other things, such as the chart's color scheme or style.
In this recipe, we'll take a chart that we created for another recipe and change the way it looks. This will give an example of how to customize the color and other parts of how the chart displays.
We'll use the same dependencies in our project.clj
file as we did in Creating scatter plots with Incanter, and this set of imports in our script or REPL:
(require '[incanter.core :as i] '[incanter.charts :as c] '[incanter.io :as iio] '[incanter.stats :as s]) (import org.jfree.chart.renderer.category.LayeredBarRenderer org.jfree.util.SortOrder)
We'll start with the chart we made in Adding lines to scatter charts. We'll keep it assigned to the iris-petal-scatter
variable.
For this example, we'll take the Iris petal scatter plot, with the line added, and we'll change the color scheme for St. Patrick's Day (lots of green).
(def colors [(java.awt.Color. 0x00 0xb3 0x66) (java.awt.Color. 0x80 0xff 0xc9)])
(doseq [[i c] (map vector (range) colors)] (.. iris-petal-scatter getPlot (getRenderer i) (setSeriesPaint 0 c)))
(i/view iris-petal-scatter)
This gives us the same chart as before, but with an updated color scheme. The updated chart looks like the following: