# Multipanel plots in Statsplots

**URL:** <https://discourse.julialang.org/t/multipanel-plots-in-statsplots/12476>\
**Category:** Visualization\
**Created:** [July 19, 2018, 12:41am UTC](https://discourse.julialang.org/t/multipanel-plots-in-statsplots/12476 "2018-07-19T00:41:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![k945](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/k945/32/8906_2.png) [@k945](https://discourse.julialang.org/u/k945)\
**Post date:** [July 19, 2018, 12:41am UTC](https://discourse.julialang.org/t/multipanel-plots-in-statsplots/12476/1 "2018-07-19T00:41:47Z")

</div>

How do you create subplots from different data frames using StatsPlots? For example, while It is possible to reuse a single data frame to to generate multiple plots

```julia
dff = DataFrame(a = 1:10, b = 10*rand(10), c = 10 * rand(10))
@df dff plot(
    plot(:a, [:b :c], colour = [:red :blue]),
    plot(:a, [:b :c], colour = [:red :blue])
)

```

what I would like to achieve is

```julia

alt = DataFrame(a = 1:10, b = 10*rand(10), c = 10 * rand(10))
alt1 = DataFrame(a = 1:10, b = 10*rand(10), c = 10 * rand(10))
@df dff alt alt1 plot(
    plot(:a, [:b :c], colour = [:red :blue]),
    plot(:a, [:b :c], colour = [:red :blue]),
    plot(:a, [:b :c], colour = [:red :blue])
)

```

---

<div class="post-metadata">

**Author:** ![k945](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/k945/32/8906_2.png) [@k945](https://discourse.julialang.org/u/k945)\
**Post date:** [July 19, 2018, 3:55am UTC](https://discourse.julialang.org/t/multipanel-plots-in-statsplots/12476/2 "2018-07-19T03:55:18Z")

</div>

There are a couple of ways to do achieve panel plots using stats plots; which I missed from the documentation:

1. one way is outlined in [advanced layouts](http://docs.juliaplots.org/latest/layouts/#advanced-layouts) and
2. from [multiple plots and sub-plots layout](http://docs.juliaplots.org/latest/tutorial/#combining-multiple-plots-as-subplots), it is possible to first create the plot objects and then create the panel plot after e.g.

```julia
df1 = DataFrame(a = 1:10, b = 10*rand(10), c = 10 * rand(10));
df2 = DataFrame(a = 1:10, b = 10*rand(10), c = 10 * rand(10))
alt = @df df1 plot( :a, [:b :c], colour = [:red :blue])
alt1 = @df df2 plot(plot( :a, [:b :c], colour = [:red :blue])
plot(df1, df2)

```

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [July 19, 2018, 6:49am UTC](https://discourse.julialang.org/t/multipanel-plots-in-statsplots/12476/3 "2018-07-19T06:49:02Z")

</div>

Given that `@df` gives you the anonymous that turns a DataFrame in a plot (if you give it only one argument), I think you could also do:

```julia
plt1, plt2 = (df1, df2) .|> @df plot(:a, [:b :c])
plot(plt1, plt2)

```

If you need the same plot on different dataset.

Feel free to make a doc PR with all the techniques that you found useful and feel were not obvious from the current docs!
