How to Plots.plot a GroupedDataFrame?

Hi there,

I recently asked a question on how to do grouping in Julia Plots, 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


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… :expressionless:

Table-specific plotting functionality for Plots is factored out to StatsPlots - although it uses a @df macro, rather than a recipe for GroupedDataFrame

1 Like