Scale.color_discrete_hue

Scale.color_discrete_hue

Create a discrete color scale to be used for the plot. Scale.color_discrete is an alias for Scale.color_discrete_hue.

Arguments

Examples

Examples

You can set a discrete color scale of your choice in a plot.

function gen_colors(n)
  cs = distinguishable_colors(n,
      [colorant"#FE4365", colorant"#eca25c"], # seed colors
      lchoices=Float64[58, 45, 72.5, 90],     # lightness choices
      transform=c -> deuteranopic(c, 0.1),    # color transform
      cchoices=Float64[20,40],                # chroma choices
      hchoices=[75,51,35,120,180,210,270,310] # hue choices
  )

  convert(Vector{Color}, cs)
end

using RDatasets

iris = dataset("datasets", "iris")

plot(iris, x=:SepalLength, y=:SepalWidth, color=:Species,
     Geom.point, Scale.color_discrete(gen_colors))
SepalLength 4 5 6 7 8 setosa versicolor virginica Species 2.0 2.5 3.0 3.5 4.0 4.5 SepalWidth

You can force the use of a discrete scale on data that would otherwise receive a continuous scale:

plot(x=rand(12), y=rand(12), color=repeat([1,2,3], outer=[4]),
     Scale.color_discrete())
x 0.0 0.5 1.0 1 2 3 Color 0.0 0.5 1.0 y

To set a default color scale for plots, you can set it in the current Theme using push_theme, using style to modify the current theme.

Gadfly.push_theme(
    style(
        discrete_color_scale=Scale.color_discrete(gen_colors)
    )
)
Gadfly.Theme(LCHab{Float32}(70.0f0,60.0f0,240.0f0), 0.9mm, 0.45mm, 1.8mm, Function[Compose.circle, Gadfly.Shape.square, Gadfly.Shape.diamond, Gadfly.Shape.cross, Gadfly.Shape.xcross, Gadfly.Shape.utriangle, Gadfly.Shape.dtriangle, Gadfly.Shape.star1, Gadfly.Shape.star2, Gadfly.Shape.hexagon, Gadfly.Shape.octagon, Gadfly.Shape.hline, Gadfly.Shape.vline], 0.3mm, :solid, nothing, nothing, 1.0, nothing, Measures.Length{:mm,Float64}[5.0mm], RGB{N0f8}(0.816,0.816,0.878), Measures.Length{:mm,Float64}[0.5mm, 0.5mm], RGB{N0f8}(0.627,0.627,0.627), 0.2mm, "'PT Sans Caption','Helvetica Neue','Helvetica',sans-serif", 2.822222222222222mm, RGB{N0f8}(0.424,0.376,0.42), "'PT Sans','Helvetica Neue','Helvetica',sans-serif", 3.880555555555555mm, RGB{N0f8}(0.337,0.29,0.333), "'PT Sans Caption','Helvetica Neue','Helvetica',sans-serif", 2.822222222222222mm, RGB{N0f8}(0.298,0.251,0.294), "'PT Sans','Helvetica Neue','Helvetica',sans-serif", 3.880555555555555mm, RGB{N0f8}(0.212,0.165,0.208), "'PT Sans','Helvetica Neue','Helvetica',sans-serif", 2.822222222222222mm, RGB{N0f8}(0.298,0.251,0.294), 40, -0.05mm, 1.0mm, 3.0mm, Gadfly.default_stroke_color, 0.3mm, Gadfly.default_discrete_highlight_color, Gadfly.default_continuous_highlight_color, Gadfly.default_lowlight_color, 0.6, Gadfly.default_middle_color, 0.6mm, :left, :square, :right, nothing, 2.0mm, 1000, 10.0, 0.5, 0.2, 4, Gadfly.Scale.DiscreteColorScale(ex-1.gen_colors, nothing, nothing, true), Gadfly.Scale.ContinuousColorScale(Gadfly.Scale.#71, Gadfly.Scale.ContinuousScaleTransform(identity, identity, Gadfly.Scale.identity_formatter), nothing, nothing))