JuliaPlots / StatsPlots.jl

Statistical plotting recipes for Plots.jl
Other
437 stars 88 forks source link

Grouping by multiple variables by @df produces errant output #490

Closed cingulate7 closed 2 years ago

cingulate7 commented 2 years ago

The 'group = (:key1, :key2)' expression in @df does not produce expected output. The following code produces a legend with 4 categories, but eight plot objects instead of four:

using DataFrames, StatsPlots

dfa = DataFrame(a = [0, 1, 0, 1, 0, 1, 0, 1],
               b = [1, 1, 1, 1, 2, 2, 2, 2],
               dat = randn(8))

@df dfa boxplot( :dat, group = (:a, :b) )

sethaxen commented 2 years ago

The first argument to boxplot should be the labels of the individual boxplots that should be plotted. Without that, it uses eachindex, and you're plotting one boxplot per data point.

Is this what you want?

@df dfa boxplot(string.(tuple.(:a, :b)), :dat; group = (:a, :b))

image

cingulate7 commented 2 years ago

thank you!!!! This has been driving me crazy all week. I will copy your solution to the other forums in which I asked it.

sethaxen commented 2 years ago

No problem!