# Create histogram with missing values

**URL:** <https://discourse.julialang.org/t/create-histogram-with-missing-values/74617>\
**Category:** General Usage\
**Tags:** macros, dataframes, plots, recipe\
**Created:** [January 14, 2022, 12:45pm UTC](https://discourse.julialang.org/t/create-histogram-with-missing-values/74617 "2022-01-14T12:45:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Norbert-droid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/norbert-droid/32/20364_2.png) [@Norbert-droid](https://discourse.julialang.org/u/Norbert-droid)\
**Post date:** [January 14, 2022, 12:45pm UTC](https://discourse.julialang.org/t/create-histogram-with-missing-values/74617/1 "2022-01-14T12:45:39Z")

</div>

I want to make a histogram with the data in a column of a data frame; the column has a lot of missing values. I don’t want to drop the missing values in the data frame or create a new array without missing values. How do I program a macro to create the histogram?

---

<div class="post-metadata">

**Author:** ![cripcate](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cripcate/32/34170_2.png) [@cripcate](https://discourse.julialang.org/u/cripcate)\
**Post date:** [January 14, 2022, 1:09pm UTC](https://discourse.julialang.org/t/create-histogram-with-missing-values/74617/2 "2022-01-14T13:09:45Z")

</div>

You can do so using `skipmissing`:

```julia
using StatsPlots

x = [4, 5, 2, 7, missing, 8]

histogram(collect(skipmissing(x)))

```

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [January 14, 2022, 3:43pm UTC](https://discourse.julialang.org/t/create-histogram-with-missing-values/74617/4 "2022-01-14T15:43:01Z")

</div>

But does any of the above comply with OP request of?

> [@Norbert-droid](#):
>
> I don’t want to … or create a new array without missing values.

The dealing of `missing's` are a real mystery to me. How are vectors and matrices containing them dealt with? We cannot have a matrix with missing nodes, however:

```julia
sizeof(missing)
0

```

which is obviously impossible. Even neutrinos have mass, and anything carrying information cannot be stored … and occupy no space.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [January 14, 2022, 4:24pm UTC](https://discourse.julialang.org/t/create-histogram-with-missing-values/74617/6 "2022-01-14T16:24:32Z")

</div>

Yes, maybe. But somewhere it must be stored the info of data memory chunks addresses because we cannot have down in the basement an array stored as  
[8bytes, 8bytes, 0, 8bytes, …].

And confess that what puzzles me more is how an image with `missings` can be stored as a 3D array in which some nodes occupy zero space.

---

<div class="post-metadata">

**Author:** ![Norbert-droid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/norbert-droid/32/20364_2.png) [@Norbert-droid](https://discourse.julialang.org/u/Norbert-droid)\
**Post date:** [January 15, 2022, 12:27am UTC](https://discourse.julialang.org/t/create-histogram-with-missing-values/74617/7 "2022-01-15T00:27:53Z")

</div>

> [@cripcate](#):
>
> `histogram(collect(skipmissing(x)))`

Thanks

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [January 15, 2022, 12:53am UTC](https://discourse.julialang.org/t/create-histogram-with-missing-values/74617/8 "2022-01-15T00:53:30Z")

</div>

I guess sizeof doesn’t include the type tag. Since there is only one value of type Missing, there is no need to store any more information about it once we know the type.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 15, 2022, 8:20am UTC](https://discourse.julialang.org/t/create-histogram-with-missing-values/74617/9 "2022-01-15T08:20:53Z")

</div>

> [@Norbert-droid](#):
>
> How do I program a macro to create the histogram?

The definition of `Plots` recipes can help to handle histograms with missing values, especially the [type recipes](https://github.com/JuliaPlots/PlotDocs.jl/blob/master/docs/src/recipes.md):

```julia
using DataFrames, Plots

df = DataFrame(a = [randn(99); missing; randn(99) .+ 2; missing; randn(99) .+ 4])

@recipe function f(v::Vector{Union{Missing, Float64}})
    seriestype --> :hist
    y = filter(!ismissing, v)
    1:length(y), y
end

histogram(df.a) # it should now work for Vectors with missings

```
