StatsPlots.jl icon indicating copy to clipboard operation
StatsPlots.jl copied to clipboard

corrplot should accept 1d column vector of symbols

Open jaakkor2 opened this issue 5 years ago • 5 comments

using StatsPlots, DataFrames, Statistics
e = DataFrame(rand(1:4,100,3))
@df e corrplot([:x1 :x2]) # ok

works, but this does not

@df e corrplot([:x1,:x2]) # not ok
ERROR: MethodError: no method matching zero(::Type{Array{Int64,1}})

Types are

julia> typeof([:x1,:x2])
Array{Symbol,1}

julia> typeof([:x1 :x2])
Array{Symbol,2}

Confer with

aggregate(e, [:x1,:x2], mean)

that works, but

aggregate(e, [:x1 :x2], mean)
ERROR: MethodError: no method matching aggregate(::DataFrame, ::Array{Symbol,2}, ::typeof(mean))

🤔

jaakkor2 avatar Jun 17 '19 17:06 jaakkor2

That's because StatsPlots is an extension to Plots, which always uses 1-row matrices for passing several series. The other syntax is from the DataFrames package (StatsPlots accepts any Table type). Are you a new StatsPlots user?

mkborregaard avatar Jun 17 '19 18:06 mkborregaard

I started evaluating StatsPlots. Have to admit it took some time to figure the syntax after having used aggregate from DataFrames.

jaakkor2 avatar Jun 17 '19 19:06 jaakkor2

Yeah, I can see that. We'd just also be hesitant to change that syntax, as it is the central idea of all of the Plots system. I'd say that it's the first time I've heard that parallel - why would you expect it to use the same syntax as aggregate?

mkborregaard avatar Jun 17 '19 19:06 mkborregaard

Seems I am not the only one https://github.com/JuliaPlots/StatsPlots.jl/issues/179

I was expecting to just list the columns, but turns out I was not reading the README.md carefully enough. In summary, a better error message would have been helpful for me.

jaakkor2 avatar Jun 17 '19 20:06 jaakkor2

Fair point!

mkborregaard avatar Jun 17 '19 21:06 mkborregaard