TidierOrg / TidierPlots.jl

Tidier data visualization in Julia, modeled after the ggplot2 R package.
MIT License
196 stars 7 forks source link

geom_point example and CairoMakie 0.12 #107

Closed dmbates closed 1 week ago

dmbates commented 4 weeks ago

Describe the bug An example in the documentation for geom_point runs when CairoMakie is constrained to v0.11 with a compat entry but fails when the compat entry is 0.11,0.12

To Reproduce

With a compat entry of CairoMakie = "0.11" in Project.toml, the example code runs fine.

julia> using DataFrames

julia> using PalmerPenguins

julia> using TidierPlots

julia> penguins = dropmissing!(DataFrame(PalmerPenguins.load()))
333×7 DataFrame
 Row │ species    island     bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex     
     │ String15   String15   Float64         Float64        Int64              Int64        String7 
─────┼──────────────────────────────────────────────────────────────────────────────────────────────
   1 │ Adelie     Torgersen            39.1           18.7                181         3750  male
   2 │ Adelie     Torgersen            39.5           17.4                186         3800  female
   3 │ Adelie     Torgersen            40.3           18.0                195         3250  female
   4 │ Adelie     Torgersen            36.7           19.3                193         3450  female
   5 │ Adelie     Torgersen            39.3           20.6                190         3650  male
   6 │ Adelie     Torgersen            38.9           17.8                181         3625  female
   7 │ Adelie     Torgersen            39.2           19.6                195         4675  male
   8 │ Adelie     Torgersen            41.1           17.6                182         3200  female
   9 │ Adelie     Torgersen            38.6           21.2                191         3800  male
  ⋮  │     ⋮          ⋮            ⋮               ⋮                ⋮               ⋮          ⋮
 326 │ Chinstrap  Dream                51.9           19.5                206         3950  male
 327 │ Chinstrap  Dream                46.8           16.5                189         3650  female
 328 │ Chinstrap  Dream                45.7           17.0                195         3650  female
 329 │ Chinstrap  Dream                55.8           19.8                207         4000  male
 330 │ Chinstrap  Dream                43.5           18.1                202         3400  female
 331 │ Chinstrap  Dream                49.6           18.2                193         3775  male
 332 │ Chinstrap  Dream                50.8           19.0                210         4100  male
 333 │ Chinstrap  Dream                50.2           18.7                198         3775  female
                                                                                    316 rows omitted

julia> ggplot(penguins, @aes(x = bill_length_mm, y = bill_depth_mm, color = species)) +
           geom_point( size = 20,
                       stroke = 1,
                       strokecolor = "black",
                       alpha = 0.2) +
           labs(x = "Bill Length (mm)", y = "Bill Width (mm)") +
           lims(x = c(40, 60), y = c(15, 20)) +
           theme_minimal()
┌ Warning: The julia equivalent of 'c(1, 2, 3)' in R is '[1, 2, 3]'.
└ @ TidierPlots ~/.julia/packages/TidierPlots/vxHk1/src/util.jl:14
┌ Warning: The julia equivalent of 'c(1, 2, 3)' in R is '[1, 2, 3]'.
└ @ TidierPlots ~/.julia/packages/TidierPlots/vxHk1/src/util.jl:14
ggplot options
data: A DataFrame (333 rows, 7 columns)
x: bill_length_mm
color: species
y: bill_depth_mm
ylabel: Bill Width (mm)
xlabel: Bill Length (mm)
limits: ((40, 60), (15, 20))

geom_point
data: inherits from plot
x: inherits from plot 
y: inherits from plot 

Running the same code after changing the compat entry for CairoMakie to 0.11,0.12 and updating the local Manifest.toml produces

julia> ggplot(penguins, @aes(x = bill_length_mm, y = bill_depth_mm, color = species)) +
           geom_point( size = 20,
                       stroke = 1,
                       strokecolor = "black",
                       alpha = 0.2) +
           labs(x = "Bill Length (mm)", y = "Bill Width (mm)") +
           lims(x = c(40, 60), y = c(15, 20)) +
           theme_minimal()
┌ Warning: The julia equivalent of 'c(1, 2, 3)' in R is '[1, 2, 3]'.
└ @ TidierPlots ~/.julia/packages/TidierPlots/vxHk1/src/util.jl:14
┌ Warning: The julia equivalent of 'c(1, 2, 3)' in R is '[1, 2, 3]'.
└ @ TidierPlots ~/.julia/packages/TidierPlots/vxHk1/src/util.jl:14
ggplot options
data: A DataFrame (333 rows, 7 columns)
x: bill_length_mm
color: species
y: bill_depth_mm
ylabel: Bill Width (mm)
xlabel: Bill Length (mm)
limits: ((40, 60), (15, 20))

geom_point
data: inherits from plot
x: inherits from plot 
y: inherits from plot 

Error showing value of type TidierPlots.GGPlot:
ERROR: Invalid attribute geom_name for plot type MakieCore.Scatter.

The available plot attributes for MakieCore.Scatter are:

alpha       colorscale    distancefield  highclip         inspector_label  markersize   overdraw  strokecolor       transparency       
color       cycle         fxaa           inspectable      lowclip          markerspace  rotation  strokewidth       uv_offset_width    
colormap    depth_shift   glowcolor      inspector_clear  marker           model        space     transform_marker  visible            
colorrange  depthsorting  glowwidth      inspector_hover  marker_offset    nan_color    ssao      transformation                       

Generic attributes are:

cycle  dim_conversions  label  model  rasterize  transformation  xautolimits  yautolimits  zautolimits                                    

Stacktrace:
  [1] validate_attribute_keys(P::Type{MakieCore.Scatter}, kw::Dict{Symbol, Any})
    @ MakieCore ~/.julia/packages/MakieCore/8S3xT/src/recipes.jl:732
  [2] MakieCore.Scatter{…}(kw::Dict{…}, args::Vector{…}, converted::Vector{…}, deregister_callbacks::Vector{…})
    @ MakieCore ~/.julia/packages/MakieCore/8S3xT/src/types.jl:86
  [3] (MakieCore.Scatter)(user_args::Tuple{Vector{Float64}, Vector{Float64}}, user_attributes::Dict{Symbol, Any})
    @ Makie ~/.julia/packages/Makie/We6MY/src/interfaces.jl:276
  [4] to_plot_object(ps::Makie.PlotSpec)
    @ Makie ~/.julia/packages/Makie/We6MY/src/specapi.jl:405
  [5] diff_plotlist!(scene::Makie.Scene, plotspecs::Vector{…}, obs_to_notify::Vector{…}, reusable_plots::IdDict{…}, plotlist::Nothing)
    @ Makie ~/.julia/packages/Makie/We6MY/src/specapi.jl:431
  [6] (::Makie.var"#update_plotlist#1113"{Makie.Scene, Nothing, Vector{…}, IdDict{…}})(plotspecs::Vector{Makie.PlotSpec})
    @ Makie ~/.julia/packages/Makie/We6MY/src/specapi.jl:464
  [7] (::Makie.var"#1112#1117"{Vector{Makie.PlotSpec}})()
    @ Makie ~/.julia/packages/Makie/We6MY/src/specapi.jl:484
  [8] lock(f::Makie.var"#1112#1117"{Vector{Makie.PlotSpec}}, l::ReentrantLock)
    @ Base ./lock.jl:229
  [9] (::Makie.var"#1111#1116"{ReentrantLock})(plotspecs::Vector{Makie.PlotSpec})
    @ Makie ~/.julia/packages/Makie/We6MY/src/specapi.jl:483
 [10] on(f::Any, observable::Observables.AbstractObservable; weak::Bool, priority::Int64, update::Bool)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:368
 [11] on
    @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:361 [inlined]
 [12] #on#215
    @ ~/.julia/packages/Makie/We6MY/src/scenes.jl:142 [inlined]
 [13] on
    @ ~/.julia/packages/Makie/We6MY/src/scenes.jl:141 [inlined]
 [14] update_plotspecs!(scene::Makie.Scene, list_of_plotspecs::Observables.Observable{Vector{Makie.PlotSpec}}, plotlist::Nothing)
    @ Makie ~/.julia/packages/Makie/We6MY/src/specapi.jl:482
 [15] update_plotspecs!
    @ ~/.julia/packages/Makie/We6MY/src/specapi.jl:452 [inlined]
 [16] update_gridlayout!(gridlayout::GridLayoutBase.GridLayout, nesting::Int64, oldgridspec::Nothing, gridspec::Makie.GridLayoutSpec, previous_contents::Vector{…}, new_layoutables::Vector{…})
    @ Makie ~/.julia/packages/Makie/We6MY/src/specapi.jl:643
 [17] (::Makie.var"#1119#1121"{Makie.GridLayoutSpec, GridLayoutBase.GridLayout, Vector{Pair{…}}, Vector{Pair{…}}})()
    @ Makie ~/.julia/packages/Makie/We6MY/src/specapi.jl:705
 [18] lock(f::Makie.var"#1119#1121"{Makie.GridLayoutSpec, GridLayoutBase.GridLayout, Vector{Pair{…}}, Vector{Pair{…}}}, l::ReentrantLock)
    @ Base ./lock.jl:229
 [19] (::Makie.var"#1118#1120"{GridLayoutBase.GridLayout, ReentrantLock, Vector{Pair{…}}, Vector{Pair{…}}})(layout_spec::Makie.GridLayoutSpec)
    @ Makie ~/.julia/packages/Makie/We6MY/src/specapi.jl:700
 [20] on(f::Any, observable::Observables.AbstractObservable; weak::Bool, priority::Int64, update::Bool)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:368
 [21] on
    @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:361 [inlined]
 [22] #on#215
    @ ~/.julia/packages/Makie/We6MY/src/scenes.jl:142 [inlined]
 [23] on
    @ ~/.julia/packages/Makie/We6MY/src/scenes.jl:141 [inlined]
 [24] update_fig!(fig::Makie.Figure, layout_obs::Observables.Observable{Makie.GridLayoutSpec})
    @ Makie ~/.julia/packages/Makie/We6MY/src/specapi.jl:699
 [25] plot!(fig::Makie.Figure, plot::MakieCore.Plot{MakieCore.plot, Tuple{Makie.GridLayoutSpec}})
    @ Makie ~/.julia/packages/Makie/We6MY/src/specapi.jl:742
 [26] _create_plot(F::Function, attributes::Dict{Symbol, Any}, args::Makie.GridLayoutSpec)
    @ Makie ~/.julia/packages/Makie/We6MY/src/figureplotting.jl:318
 [27] plot(args::Makie.GridLayoutSpec)
    @ MakieCore ~/.julia/packages/MakieCore/8S3xT/src/recipes.jl:39
 [28] draw_ggplot(plot::TidierPlots.GGPlot)
    @ TidierPlots ~/.julia/packages/TidierPlots/vxHk1/src/draw.jl:0
 [29] (::TidierPlots.var"#213#214"{TidierPlots.GGPlot})()
    @ TidierPlots ~/.julia/packages/TidierPlots/vxHk1/src/show.jl:76
 [30] (::Makie.var"#337#338"{@Kwargs{}, TidierPlots.var"#213#214"{TidierPlots.GGPlot}, MakieCore.Attributes})()
    @ Makie ~/.julia/packages/Makie/We6MY/src/theming.jl:230
 [31] lock(f::Makie.var"#337#338"{@Kwargs{}, TidierPlots.var"#213#214"{TidierPlots.GGPlot}, MakieCore.Attributes}, l::ReentrantLock)
    @ Base ./lock.jl:229
 [32] #with_theme#336
    @ ~/.julia/packages/Makie/We6MY/src/theming.jl:226 [inlined]
 [33] with_theme
    @ ~/.julia/packages/Makie/We6MY/src/theming.jl:225 [inlined]
 [34] show(io::IOContext{Base.TTY}, plot::TidierPlots.GGPlot)
    @ TidierPlots ~/.julia/packages/TidierPlots/vxHk1/src/show.jl:75
 [35] show(io::IOContext{Base.TTY}, ::MIME{Symbol("text/plain")}, x::TidierPlots.GGPlot)
    @ Base.Multimedia ./multimedia.jl:47
 [36] (::REPL.var"#55#56"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)
    @ REPL ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/REPL/src/REPL.jl:273
 [37] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/REPL/src/REPL.jl:569
 [38] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/REPL/src/REPL.jl:259
 [39] display(d::REPL.REPLDisplay, x::Any)
    @ REPL ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/REPL/src/REPL.jl:278
 [40] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:340
 [41] #invokelatest#2
    @ ./essentials.jl:892 [inlined]
 [42] invokelatest
    @ ./essentials.jl:889 [inlined]
 [43] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/REPL/src/REPL.jl:315
 [44] (::REPL.var"#57#58"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/REPL/src/REPL.jl:284
 [45] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/REPL/src/REPL.jl:569
 [46] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/REPL/src/REPL.jl:282
 [47] (::REPL.var"#do_respond#80"{…})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/REPL/src/REPL.jl:911
 [48] (::VSCodeServer.var"#103#106"{REPL.var"#do_respond#80"{…}})(mi::REPL.LineEdit.MIState, buf::IOBuffer, ok::Bool)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.79.2/scripts/packages/VSCodeServer/src/repl.jl:122
 [49] #invokelatest#2
    @ ./essentials.jl:892 [inlined]
 [50] invokelatest
    @ ./essentials.jl:889 [inlined]
 [51] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/REPL/src/LineEdit.jl:2656
 [52] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/REPL/src/REPL.jl:1312
Some type information was truncated. Use `show(err)` to see complete types.

Additional context

julia> using Pkg; Pkg.status()
Project EmbraceUncertainty v0.1.0
Status `~/projects/EmbraceUncertainty/Project.toml`
  [cbdf2221] AlgebraOfGraphics v0.6.19
  [69666777] Arrow v2.7.2
  [6e4b80f9] BenchmarkTools v1.5.0
  [336ed68f] CSV v0.10.14
  [13f3f980] CairoMakie v0.12.2
  [324d7699] CategoricalArrays v0.10.8
  [8be319e6] Chain v0.6.0
  [9a962f9c] DataAPI v1.16.0
  [75880514] DataFrameMacros v0.4.1
  [a93c6f00] DataFrames v1.6.1
  [31c24e10] Distributions v0.25.109
  [8f03c58b] Effects v1.2.0
  [da1fdf0e] FreqTables v0.4.6
  [38e38edf] GLM v1.9.0
  [7073ff75] IJulia v1.24.2
  [ff71e718] MixedModels v4.24.1
  [7e9fb7ac] MixedModelsDatasets v0.1.1
  [b12ae82c] MixedModelsMakie v0.4.3
  [76087f3c] NLopt v1.0.2
  [2dfb63ee] PooledArrays v1.4.3
  [6f49c342] RCall v0.14.1
  [27983f2f] RectangularFullPacked v0.2.0
  [6c6a2e73] Scratch v1.2.1
  [5064a6a7] StandardizedPredictors v1.0.1
  [82ae8749] StatsAPI v1.7.0
  [2913bbd2] StatsBase v0.34.3
  [3eaba693] StatsModels v0.7.3
  [bd369af6] Tables v1.11.1
  [9d95f2ec] TypedTables v1.4.6
  [a5390f91] ZipFile v0.10.1
  [ade2ca70] Dates
  [f43a241f] Downloads v1.6.0
  [37e2e46d] LinearAlgebra
  [d6f4376e] Markdown
  [44cfe95a] Pkg v1.10.0
  [9a3f8284] Random
  [ea8e919c] SHA v0.7.0
dmbates commented 4 weeks ago

In case it matters

julia> versioninfo()
Julia Version 1.10.4
Commit 48d4fd48430 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M1 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 6 default, 0 interactive, 3 GC (on 6 virtual cores)
Environment:
  JULIA_EDITOR = code
rdboyes commented 3 weeks ago

Thanks for reporting this! I think this has to do with an update in Makie 0.21 that errors on unsupported keywords. Previous versions of Makie would disregard unsupported keyword arguments without error. We already have a system in place to filter out "internal" arguments so they don't make it past the TidierPlots machinery, so I just need to update that to catch geom_name as well. It should be fixed in the next patch version!

dmbates commented 3 weeks ago

Thanks for addressing this.

rdboyes commented 1 week ago

This should be addressed now - 0.7.7 will release as soon as it merges