# Re-use existing StatsPlots Recipes?

**URL:** https://discourse.julialang.org/t/re-use-existing-statsplots-recipes/35104
**Category:** General Usage
**Tags:** question, plotting, recipe
**Created:** [February 25, 2020, 8:30am UTC](https://discourse.julialang.org/t/re-use-existing-statsplots-recipes/35104 "2020-02-25T08:30:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [February 25, 2020, 8:30am UTC](https://discourse.julialang.org/t/re-use-existing-statsplots-recipes/35104/1 "2020-02-25T08:30:17Z")

</div>

I’m trying to define a `stackedhist` recipes which takes `bins` and `array{array}` and uses [groupedbar](https://github.com/JuliaPlots/StatsPlots.jl#grouped-bar-plots) to display a stacked histogram, the following **function** works:

```julia
using StatsPlots, StatsBase
function stack_plot(args...)
    bins = args[1] 
    # the weights of bar chart are vertical vector
    weights_ary = mapreduce(x->fit(StatsBase.Histogram, x, bins).weights, hcat, args[2])
    
    groupedbar(bins[1:end-1], weights_ary, bar_position = :stack)
end

stack_plot(0:0.1:1, [randn(100), randn(100)])

```

However, the following recipe does not work:

```julia
using StatsPlots, StatsBase
@userplot StackedHist
@recipe function f(h::StackedHist)
    seriestype := :groupedbar
    bar_position = :stack
    bins = h.args[1] 
    # the weights of bar chart are vertical vector
    weights_ary = mapreduce(x->fit(StatsBase.Histogram, x, bins).weights, hcat, h.args[2])
    
    bins[1:end-1], weights_ary
end

###
ERROR: The backend must not support the series type Val{:groupedbar}, and there isn't a series recipe defined.

```

Am I doing something obvious+stupid thing here?

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [February 25, 2020, 11:50am UTC](https://discourse.julialang.org/t/re-use-existing-statsplots-recipes/35104/2 "2020-02-25T11:50:39Z")

</div>

It’s just that `groupedbar` is not a `series recipe` and thus cannot be used as a `seriestype`. Instead, return

```julia
RecipesBase.recipetype(:groupedbar, bins[1:end-1], weights_ary)

```

from the recipe
