How to handle missings in CairoMakie

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.

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)

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?

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.

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

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

1 Like

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