How to color points in scatter plot by value?

With VegaLite.jl:

using VegaLite, DataFrames

df = DataFrame(x=randn(100), y=randn(100), z=randn(100))

df |> @vlplot(:point, x=:x, y=:y, color=:z)

example1

You can customize the color scale with any of the pre-defined color schemes:

df |> @vlplot(:point, x=:x, y=:y, color={:z, scale={scheme=:plasma}})

example2

You can also go entirely custom by specifying a custom piecewise scale:

df |>
@vlplot(
  :point,
  x=:x,
  y=:y,
  color={
    :z,
    scale={
      domain=[-3, -1, 1, 3], 
      range=[:red, :blue, :green, :yellow]
    }
  }
)

example3

And yes, I am aware that my custom color scheme example is probably a strong argument to go with the pre-defined schemes :wink:

6 Likes