# Multipanel plots in Statsplots

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

``````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

``````
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])
)
``````

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 and
2. from multiple plots and sub-plots layout, it is possible to first create the plot objects and then create the panel plot after e.g.
``````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)
``````

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:

``````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!

2 Likes