-
Notifications
You must be signed in to change notification settings - Fork 250
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
Custom statistics #894
Comments
Yes!: # This uses davidavdav/CHull.jl
using DataFrames, CHull
type ChullStatistic <: Gadfly.StatisticElement
end
function Gadfly.input_aesthetics(stat::ChullStatistic)
return [:x, :y]
end
function Gadfly.output_aesthetics(stat::ChullStatistic)
return [:x, :y]
end
function Gadfly.default_scales(stat::ChullStatistic)
return [Gadfly.Scale.x_continuous(), Gadfly.Scale.y_continuous()]
end
function Gadfly.Stat.apply_statistic(stat::ChullStatistic,
scales::Dict{Symbol, Gadfly.ScaleElement},
coord::Gadfly.CoordinateElement,
aes::Gadfly.Aesthetics)
xy = hcat(aes.x, aes.y)
p = chull(xy)
hull = p.points[p.vertices,:]
hull = vcat(hull, hull[1,:]')
aes.x = hull[:,1]
aes.y = hull[:,2]
end
Stat_chull = ChullStatistic
D = DataFrame(x=randn(50), y=randn(50))
layer1 = layer(Geom.point)
layer2 = layer(Stat_chull, Geom.path)
p = plot(D, x=:x, y=:y, layer1, layer2) |
I think it would be good to add a page to the Gadfly documentation titled "Custom statistics and custom geometries", which includes examples as above. |
That sounds like a fantastic idea. The only thing I don't like about the given example is that it has another dependency. I don't have to time to create the example myself, but if you want to go for it, I'll gladly review it and merge it. |
Do you think it would be possible to update this to not use an outside dependency? I don't want the Gadfly docs to get too hard to build, that's the only reason. I think it would be great to have this in the docs. If you need help with the new style of docs, Documenter.jl has some pretty decent examples: https://juliadocs.github.io/Documenter.jl/latest/ |
Does Gadfly support custom statistics?
The text was updated successfully, but these errors were encountered: