Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using JuliaDB/IndexedTables with Gadfly #94

Open
cmcaine opened this issue Jun 27, 2019 · 4 comments
Open

Using JuliaDB/IndexedTables with Gadfly #94

cmcaine opened this issue Jun 27, 2019 · 4 comments

Comments

@cmcaine
Copy link

cmcaine commented Jun 27, 2019

So I'm just trying to get Gadfly to plot an IndexedTable I've produced with the JuliaDB.table function.

The IterableTables documentation claims to support JuliaDB tables as data sources and Gadfly as a sink, but I'm doing it wrong and/or it doesn't work for me

Complete example:

julia> using IterableTables, JuliaDB, Gadfly

julia> t = table(1:10, (1:10) * 3, names = (:x, :y))
Table with 10 rows, 2 columns:
x   y
──────
1   3
2   6
3   9
4   12
5   15
6   18
7   21
8   24
9   27
10  30

julia> typeof(t)
IndexedTable{StructArrays.StructArray{NamedTuple{(:x, :y),Tuple{Int64,Int64}},1,NamedTuple{(:x, :y),Tuple{Array{Int64,1},Array{Int64,1}}}}}

julia> plot(t, x=:x, y=:y, Geom.point)
ERROR: MethodError: no method matching evalmapping(::IndexedTable{StructArrays.StructArray{NamedTuple{(:x, :y),Tuple{Int64,Int64}},1,NamedTuple{(:x, :y),Tuple{Array{Int64,1},Array{Int64,1}}}}}, ::Symbol)

```Closest candidates are:
  evalmapping(::Any, ::AbstractArray) at /home/colin/.julia/packages/Gadfly/09PWZ/src/mapping.jl:185
  evalmapping(::Any, ::Function) at /home/colin/.julia/packages/Gadfly/09PWZ/src/mapping.jl:186
  evalmapping(::Any, ::Distributions.Distribution) at /home/colin/.julia/packages/Gadfly/09PWZ/src/mapping.jl:187
  ...
Stacktrace:
 [1] evalmapping!(::Dict{Symbol,Any}, ::IndexedTable{StructArrays.StructArray{NamedTuple{(:x, :y),Tuple{Int64,Int64}},1,NamedTuple{(:x, :y),Tuple{Array{Int64,1},Array{Int64,1}}}}}, ::Gadfly.Data) at /home/colin/.julia/packages/Gadfly/09PWZ/src/mapping.jl:220
 [2] #plot#65(::Base.Iterators.Pairs{Symbol,Symbol,Tuple{Symbol,Symbol},NamedTuple{(:x, :y),Tuple{Symbol,Symbol}}}, ::Function, ::IndexedTable{StructArrays.StructArray{NamedTuple{(:x, :y),Tuple{Int64,Int64}},1,NamedTuple{(:x, :y),Tuple{Array{Int64,1},Array{Int64,1}}}}}, ::Type{Gadfly.Geom.PointGeometry}) at /home/colin/.julia/packages/Gadfly/09PWZ/src/Gadfly.jl:327
 [3] (::getfield(Gadfly, Symbol("#kw##plot")))(::NamedTuple{(:x, :y),Tuple{Symbol,Symbol}}, ::typeof(plot), ::IndexedTable{StructArrays.StructArray{NamedTuple{(:x, :y),Tuple{Int64,Int64}},1,NamedTuple{(:x, :y),Tuple{Array{Int64,1},Array{Int64,1}}}}}, ::Type{Gadfly.Geom.PointGeometry}) at ./none:0
 [4] top-level scope at none:0
@cmcaine
Copy link
Author

cmcaine commented Jun 27, 2019

This does work for VegaLite, though, which is nice.

using VegaLite
t |> @vlplot(
    :point,
    x = :x,
    y = :y)

@davidanthoff
Copy link
Member

Support for Gadfly.jl hasn't survived the transition to julia 1.0, I'm afraid...

I had a brief look how difficult it would be to reenable it, and the old strategy won't work anymore... I'll think a little how we could sort this out.

I think in the meantime, what should work is to convert the JuliaDB table to a DataFrame and then pass that to Gadfly. Not exactly elegant, but might do the trick.

@davidanthoff
Copy link
Member

@cmcaine
Copy link
Author

cmcaine commented Jun 30, 2019

I think in the meantime, what should work is to convert the JuliaDB table to a DataFrame and then pass that to Gadfly. Not exactly elegant, but might do the trick.

Yes, this is what I ended up doing:

import IndexedTables
import Gadfly

Gadfly.plot(data_source::IndexedTables.IndexedTable, 
	    elements::Union{Array{Gadfly.Layer,1}, Function, Gadfly.Element, Gadfly.Theme, Type}...;
	    mapping...) =
  Gadfly.plot(data_source |> DataFrame, elements...; mapping...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants