# How to color points in scatter plot by value?

**URL:** <https://discourse.julialang.org/t/how-to-color-points-in-scatter-plot-by-value/11740>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [June 17, 2018, 11:03pm UTC](https://discourse.julialang.org/t/how-to-color-points-in-scatter-plot-by-value/11740 "2018-06-17T23:03:16Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [June 18, 2018, 1:09am UTC](https://discourse.julialang.org/t/how-to-color-points-in-scatter-plot-by-value/11740/3 "2018-06-18T01:09:07Z")

</div>

With [VegaLite.jl](https://github.com/fredo-dedup/VegaLite.jl):

```julia
using VegaLite, DataFrames

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

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

```

![example1](https://global.discourse-cdn.com/julialang/original/3X/f/1/f1f19fa8718b56c8f93c0228e4b39b0f6874606d.png)

You can customize the color scale with any of the [pre-defined color schemes](https://vega.github.io/vega/docs/schemes/#seq-multi-hue):

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

```

![example2](https://global.discourse-cdn.com/julialang/original/3X/a/1/a10a4c190c6fef434555860d095cc7ab2b2f63b5.png)

You can also go entirely custom by specifying a [custom piecewise scale](https://vega.github.io/vega-lite/docs/scale.html#piecewise):

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

```

![example3](https://global.discourse-cdn.com/julialang/original/3X/1/7/17b8e7544c4ffc02a7b8d7e654732402d27e0af8.png)

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

---

_[View the full topic](https://discourse.julialang.org/t/how-to-color-points-in-scatter-plot-by-value/11740)._
