# How to Plots.plot a GroupedDataFrame?

**URL:** <https://discourse.julialang.org/t/how-to-plots-plot-a-groupeddataframe/41723>\
**Category:** General Usage\
**Tags:** plots\
**Created:** [June 19, 2020, 12:02pm UTC](https://discourse.julialang.org/t/how-to-plots-plot-a-groupeddataframe/41723 "2020-06-19T12:02:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gedankenexperiment](https://avatars.discourse-cdn.com/v4/letter/g/a183cd/32.png) [@gedankenexperiment](https://discourse.julialang.org/u/gedankenexperiment)\
**Post date:** [June 19, 2020, 12:02pm UTC](https://discourse.julialang.org/t/how-to-plots-plot-a-groupeddataframe/41723/1 "2020-06-19T12:02:35Z")

</div>

Hi there,

I recently asked a question on how to do [grouping in Julia Plots](https://discourse.julialang.org/t/grouping-in-julia-plots/41596), the answer was to encapsulate a mapping and feed the function to the group keyword in the plot function.

But learning more about DataFrames, I came across the GroupedDataFrame object. It would be quite useful to exploit this grouping with the plot function. I did not find any info on this besides how to index a GroupedDataFrame. Also not clear how to ungroup the object to obtain a DataFrame. Maybe some of you are more familiar with the compatibility of GroupedDataFrame and Plots.plot? Many thanks in advance.

I guess I could do sth like

```julia

DF=groupby(DataFrame(x=1:10,y=1:10,cases=repeat([1,2,3,4,5],2)),:cases)
# I would like to group e.g. cases 1,2 and 3,4,5 together!
plot(DF[1].x,DF[1].y)

for i in 2:length(DF)
     plot!(DF[i].x,DF[i].y)
end

```

…but this doesn’t work anyways and doesn’t really make use of the grouping… 😑

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 19, 2020, 12:28pm UTC](https://discourse.julialang.org/t/how-to-plots-plot-a-groupeddataframe/41723/2 "2020-06-19T12:28:46Z")

</div>

Table-specific plotting functionality for Plots is factored out to [StatsPlots](https://github.com/JuliaPlots/StatsPlots.jl) - although it uses a `@df` macro, rather than a recipe for `GroupedDataFrame`
