# How to handle missings in CairoMakie

**URL:** <https://discourse.julialang.org/t/how-to-handle-missings-in-cairomakie/61566>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [May 21, 2021, 8:29am UTC](https://discourse.julialang.org/t/how-to-handle-missings-in-cairomakie/61566 "2021-05-21T08:29:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vjd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vjd/32/2644_2.png) [@vjd](https://discourse.julialang.org/u/vjd)\
**Post date:** [May 21, 2021, 8:29am UTC](https://discourse.julialang.org/t/how-to-handle-missings-in-cairomakie/61566/1 "2021-05-21T08:29:00Z")

</div>

How does one handle `missing` in plots?

I am on `[13f3f980] CairoMakie v0.4.5`

Reproducer below. I haven’t grouped by `id` below, but besides that point, how do we plot `dv2`. The only way I can see doing that now is to create a non-missing vector of dv2 and then chop the time vector to be of equal length for the second scatter that is commented out.

```julia
dd = DataFrame(id = [1,1,1,1,1,2,2,2,2,2],
               time = [10,20, 30, 40, 50, 10,20, 30, 40, 50],
               dv = [5.0, 4.0, 3.0, 2.0, 1.0,10.0, 9.0, 8.0, 7.0, 6.0],
               dv2 = [5.0, 4.0, 3.0, 2.0, missing,10.0, 9.0, 8.0, 7.0, missing])
#
fig = Figure(resolution = (1000, 700))
ax1 = fig[1, 1] = Axis(fig, 
  title = "",
  xlabel="Time (min)", 
  ylabel="Concentration (μg/L)")               
scatter!(ax1, 
  dd[!,:time], dd[!,:dv])
# scatter!(ax1, 
# dd[!,:time], dd[!,:dv2]) 
fig

```

[Update]

When I filter out the `missing` in `dv2`, and plot, the resulting `Vector{Union{Missing, Float64}} ` generates a plot that does not make sense (or obviously I am doing something wrong)

```julia
dd2 = filter(x-> !ismissing.(x.dv2), dd)
fig2 = Figure(resolution = (1000, 700))
ax2 = fig2[1, 1] = Axis(fig2, 
  title = "",
  xlabel="Time (min)", 
  ylabel="Concentration (μg/L)")               
# scatter!(ax2, 
# dd2[!,:time], dd2[!,:dv])
scatter!(ax2, 
   dd2[!,:time], dd2[!,:dv2]) 
fig2

```

Why are the concentrations increasing here? they should decrease with time based on the dataset?

 ![2021-05-21 at 4.38 AM](https://global.discourse-cdn.com/julialang/original/3X/7/6/76d45c7fe8dc3eb2872772a28a1d8b0973089c81.png)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [May 21, 2021, 8:35am UTC](https://discourse.julialang.org/t/how-to-handle-missings-in-cairomakie/61566/2 "2021-05-21T08:35:53Z")

</div>

I assume you are seeing that a vector from `1:n` is plotted instead of `dv2`, right? That was a conversion problem we fixed recently, can you try with the latest CairoMakie / Makie? That should just convert missing to NaN internally, so the scatters should just be missing.

---

<div class="post-metadata">

**Author:** ![vjd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vjd/32/2644_2.png) [@vjd](https://discourse.julialang.org/u/vjd)\
**Post date:** [May 21, 2021, 8:40am UTC](https://discourse.julialang.org/t/how-to-handle-missings-in-cairomakie/61566/3 "2021-05-21T08:40:03Z")

</div>

is that the reason for the plot I just updated above, @jules

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [May 21, 2021, 8:41am UTC](https://discourse.julialang.org/t/how-to-handle-missings-in-cairomakie/61566/4 "2021-05-21T08:41:21Z")

</div>

Yes basically the old version didn’t recognize missing vectors and converted those to a “pseudo-categorical” version, which was just 1:n with the values as tick values, but that’s clearly a bad way to do it

---

<div class="post-metadata">

**Author:** ![vjd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vjd/32/2644_2.png) [@vjd](https://discourse.julialang.org/u/vjd)\
**Post date:** [May 21, 2021, 9:07am UTC](https://discourse.julialang.org/t/how-to-handle-missings-in-cairomakie/61566/5 "2021-05-21T09:07:51Z")

</div>

I ended up doing `dd!, :dv2] = coalesce.(dd[!, :dv2], NaN)` for now and I was able to use it and get the correct plot
