# Issue with AlgebraOfGraphics.jl: MethodError when using data(df)

**URL:** <https://discourse.julialang.org/t/issue-with-algebraofgraphics-jl-methoderror-when-using-data-df/126795>\
**Category:** General Usage\
**Tags:** package, plotting, dataframes, algebraofgraphics\
**Created:** [March 10, 2025, 10:41pm UTC](https://discourse.julialang.org/t/issue-with-algebraofgraphics-jl-methoderror-when-using-data-df/126795 "2025-03-10T22:41:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Margot\_Geisbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/margot_geisbauer/32/215714_2.png) [@Margot\_Geisbauer](https://discourse.julialang.org/u/Margot_Geisbauer)\
**Post date:** [March 10, 2025, 10:41pm UTC](https://discourse.julialang.org/t/issue-with-algebraofgraphics-jl-methoderror-when-using-data-df/126795/1 "2025-03-10T22:41:15Z")

</div>

I’m trying to plot timing data using `AlgebraOfGraphics.jl` and `CairoMakie.jl`. My data consists of timestamps (in seconds) and hit types (`early`, `perfect`, `late`). The hit types are mapped to numeric values:

- `"early"` → `-1.0`
- `"perfect"` → `0.0`
- `"late"` → `1.0`

I create a `DataFrame` from the data and pass it to `data(df)`, but I keep getting a `MethodError`. Here’s my code:

```using
using AlgebraOfGraphics
using CairoMakie
using DataFrames

function load_json(filepath)
    open(filepath, "r") do file
        return JSON.parse(file)
    end
end

function process_data(json_data)
    times = []
    hit_types = []
    
    for entry in json_data
        for miss in entry["Details"]["miss"]
            time = miss["time"]
            offset = entry["Details"]["offset"]
            
            if offset < 0
                hit_type = "early"
            elseif offset == 0
                hit_type = "perfect"
            else
                hit_type = "late"
            end
            
            push!(times, time)
            push!(hit_types, hit_type)
        end
    end
    println(times)
println(hit_types)

    return times, hit_types
end

function plot_hits(times, hit_types)
    hit_mapping = Dict("early" => -1.0, "perfect" => 0.0, "late" => 1.0)
    hit_nums = [hit_mapping[hit] for hit in hit_types]

    times_clean = Float64.(collect(times))
    hit_nums_clean = Float64.(collect(hit_nums))

    df = DataFrame(time=times_clean, hit_type=hit_nums_clean)

    column_table = Tables.columntable(df)
    spec = data(column_table) * mapping(:time, :hit_type) * visual(Lines)

    spec |> draw
end

json_filepath = "Implementierung/src/return.json"
json_data = load_json(json_filepath)
times, hit_types = process_data(json_data)
plot_hits(times, hit_types)

```

The `DataFrame` looks fine:  
10×2 DataFrame  
Row │ time hit\_type  
─────┼───────────────────  
1 │ 0.0 0.0  
2 │ 15.0 1.0  
3 │ 8.0 1.0  
4 │ 14.0 1.0  
5 │ 6.0 1.0  
6 │ 10.0 1.0  
7 │ 7.0 1.0  
8 │ 12.0 1.0  
9 │ 15.0 1.0  
10 │ 9.0 1.0

When I run the function, I get the following error:

ERROR: MethodError: objects of type Vector{Any} are not callable  
Use square brackets for indexing an Array.  
The object of type `Vector{Any}` exists, but no method is defined for this combination of argument types when trying to treat it as a callable object.  
Stacktrace:  
[1] plot\_hits(times::Vector{Any}, hit\_types::Vector{Any})  
@ Main c:\Users\margo\JuliaRepo\j2\Implementierung\src\TimeGraph.jl:55  
[2] top-level scope  
@ c:\Users\margo\JuliaRepo\j2\Implementierung\src\TimeGraph.jl:63

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [March 10, 2025, 11:45pm UTC](https://discourse.julialang.org/t/issue-with-algebraofgraphics-jl-methoderror-when-using-data-df/126795/2 "2025-03-10T23:45:55Z")

</div>

Why don’t the stack trace’s line numbers match the code you shared? The code only has 56 lines, the stack trace starts at line 63. If we treat the `plot_hits` call on the last line as line 63 instead, then line 55 would be `spec = ...`, so `data, mapping, visual` are called, worth a type check.
