-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds PlottableData struct, introduces the idea of transform functions…
… to eventually support custom scales
- Loading branch information
Showing
9 changed files
with
103 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
geom_tile = geom_template("geom_tile", ["x", "y", "z"], :Heatmap) | ||
geom_contour = geom_template("geom_contour", ["x", "y"], :Contour; aes_function = stat_density_2d) | ||
|
||
function stat_density_2d(aes_dict::Dict{String, Symbol}, | ||
args_dict::Dict{String, Any}, required_aes::Vector{String}, plot_data::DataFrame) | ||
args_dict, required_aes::Vector{String}, plot_data::DataFrame) | ||
|
||
x = plot_data[!, aes_dict["x"]] | ||
y = plot_data[!, aes_dict["y"]] | ||
|
||
k = kde((penguins.bill_length_mm, penguins.bill_depth_mm)) | ||
k = kde((x, y)) | ||
|
||
required_aes = ["z"] | ||
|
||
return_data = DataFrame( | ||
"z" => k.density | ||
) | ||
aes_dict["z"] = :z | ||
delete!(aes_dict, "x") | ||
delete!(aes_dict, "y") | ||
|
||
return_data = Dict(:z => k.density) | ||
|
||
return (aes_dict, args_dict, required_aes, return_data) | ||
end | ||
end | ||
|
||
geom_tile = geom_template("geom_tile", ["x", "y", "z"], :Heatmap) | ||
geom_contour = geom_template("geom_contour", ["x", "y"], :Contour; aes_function = stat_density_2d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# transformation functions for aes specification | ||
# they all should return a Dict that maps a aes symbol | ||
# to a PlottableData struct which contains | ||
|
||
# - position: the data | ||
# - label_target: where should the labels go? | ||
# - label_function: what should be done to data in "position" to display it | ||
# - makie_function: what should be done before data goes to the Makie arg | ||
|
||
struct PlottableData | ||
position::Any | ||
makie_function::Function | ||
label_target::Union{Symbol, Nothing} | ||
label_function::Any | ||
end | ||
|
||
# simplest one is as_is, which just gets the column | ||
# exactly as it is in the DataFrame | ||
|
||
function as_is(target::Symbol, data::DataFrame) | ||
return Dict{Symbol, PlottableData}( | ||
target => PlottableData(data[!, target], | ||
identity, | ||
Symbol(String(target) * "ticks"), | ||
Makie.automatic | ||
) | ||
) | ||
end | ||
|
||
# categorical array handling options for String columns | ||
|
||
function cat_inorder(target::Symbol, data::DataFrame) | ||
cat_column = data[!, target] | ||
cat_array = CategoricalArray(cat_column, | ||
levels = unique(cat_column), | ||
ordered = true) | ||
return Dict{Symbol, PlottableData}( | ||
target => PlottableData( | ||
levelcode.(cat_array), | ||
x -> levels(x) | ||
) | ||
) | ||
end | ||
|
||
function cat_inseq(target::Symbol, data::DataFrame) | ||
cat_array = CategoricalArray(data[!, target]) | ||
return Dict{Symbol, PlottableData}( | ||
target => PlottableData( | ||
levelcode.(cat_array), | ||
x -> levels(x) | ||
) | ||
) | ||
end | ||
|
||
# kernel density estimation for geom_contour | ||
|
||
function kernel_density_2d(x::Symbol, y::Symbol, data::DataFrame) | ||
|
||
k = kde((data[!, x], data[!, y])) | ||
|
||
return Dict{Symbol, PlottableData}( | ||
:x => PlottableData(k.x, identity), | ||
:y => PlottableData(k.y, identity), | ||
:z => PlottableData(k.density, identity) | ||
) | ||
end |