# Boxplot with NaN / missing / Inf in data?

**URL:** <https://discourse.julialang.org/t/boxplot-with-nan-missing-inf-in-data/112966>\
**Category:** New to Julia\
**Tags:** question, plotting\
**Created:** [April 15, 2024, 1:47pm UTC](https://discourse.julialang.org/t/boxplot-with-nan-missing-inf-in-data/112966 "2024-04-15T13:47:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [April 15, 2024, 1:47pm UTC](https://discourse.julialang.org/t/boxplot-with-nan-missing-inf-in-data/112966/1 "2024-04-15T13:47:16Z")

</div>

Hello everyone,

I’m struggling at the moment with boxplots. My data has several data points and many of them is NaN or Inf or missing. I was wondering if there is a way to just ignore these values without trying to edit data itself?

A simple example can be like this:

```julia
boxplot([1, 2, 3, NaN, 20, 1, 2, 7, 3])

```

Error:

```julia
ERROR: ArgumentError: quantiles are undefined in presence of NaNs or missing values
Stacktrace:
  [1] _quantilesort!(v::Vector{Float64}, sorted::Bool, minp::Float64, maxp::Float64)
    @ Statistics ~/.julia/juliaup/julia-1.10.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Statistics/src/Statistics.jl:994
  [2] #quantile!#49
    @ ~/.julia/juliaup/julia-1.10.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Statistics/src/Statistics.jl:964 [inlined]
  [3] quantile!
    @ ~/.julia/juliaup/julia-1.10.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Statistics/src/Statistics.jl:960 [inlined]
  [4] quantile(v::Vector{…}, p::StepRangeLen{…}; sorted::Bool, alpha::Float64, beta::Float64)
    @ Statistics ~/.julia/juliaup/julia-1.10.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Statistics/src/Statistics.jl:1089
  [5] macro expansion
    @ ~/.julia/packages/StatsPlots/cStOe/src/boxplot.jl:41 [inlined]
  [6] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, ::Type{Val{:boxplot}}, x::Any, y::Any, z::Any)
    @ StatsPlots ~/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl:300
  [7] _process_seriesrecipe(plt::Any, plotattributes::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/series_recipe.jl:50
  [8] _process_seriesrecipes!(plt::Any, kw_list::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/series_recipe.jl:27
  [9] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/RecipesPipeline.jl:99
 [10] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/a3u1v/src/plot.jl:223
 [11] plot(args::Any; kw...)
    @ Plots ~/.julia/packages/Plots/a3u1v/src/plot.jl:102
 [12] boxplot(args::Any; kw...)
    @ Plots ~/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl:427
 [13] top-level scope
    @ Untitled-1:282
Some type information was truncated. Use `show(err)` to see complete types.

```

---

<div class="post-metadata">

**Author:** ![filchristou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/filchristou/32/26760_2.png) [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Post date:** [April 15, 2024, 1:53pm UTC](https://discourse.julialang.org/t/boxplot-with-nan-missing-inf-in-data/112966/2 "2024-04-15T13:53:45Z")

</div>

The easiest thing would be to filter the data, either using an iterator or a by making a new list. For missing values, there is `skipmissing` exactly for that.

```julia
skipmissing([1,2,missing,3]) # return an iterator

```

From the iterator you can create a list using `collect`

```julia
collect(skipmissing([1,2,missing,3]))

```

That’s only for `missing` values.  
If you want to filter more, you need to write your own filter.  
E.g.

```julia
julia> filter(x-> x !== NaN, [1, 3, NaN])
2-element Vector{Float64}:
 1.0
 3.0

```

Prepend that with the `Iterators` module to get an iterator instead.

```julia
julia> Iterators.filter(x-> x !== NaN, [1, 3, NaN])
Base.Iterators.Filter{var"#7#8", Vector{Float64}}(var"#7#8"(), [1.0, 3.0, NaN])

```

You also might be interested in Skipper.jl  
It short of generilizes the skipmissing for custom predicates.
