Julia 用牛虻处理统计数据

Julia 用牛虻处理统计数据,julia,gadfly,Julia,Gadfly,我想扩展Gadfly包以匹配我自己的特殊偏好。然而,我很难理解如何使用Gadfly的统计数据,以便在绘图之前对其输出进行处理 例如,假设我想使用Stat.histogram生成的x,y美学。要将这些添加到绘图中,我知道我可以将Stat.histogram作为参数包含在layer()中。但是如果我想使用Stat.histogram来计算x,y美学,用我自己的代码编辑它们,然后绘制这些编辑后的美学,我该怎么办 我正在寻找一个像load\u美学(layer(x=x,Stat.histogram))这样

我想扩展Gadfly包以匹配我自己的特殊偏好。然而,我很难理解如何使用Gadfly的统计数据,以便在绘图之前对其输出进行处理

例如,假设我想使用Stat.histogram生成的x,y美学。要将这些添加到绘图中,我知道我可以将
Stat.histogram
作为参数包含在
layer()
中。但是如果我想使用Stat.histogram来计算x,y美学,用我自己的代码编辑它们,然后绘制这些编辑后的美学,我该怎么办


我正在寻找一个像
load\u美学(layer(x=x,Stat.histogram))
这样的函数,或者一个像
layer(x=x,Stat.histogram)这样的字段。美学

您可以创建自己的统计数据。参见

根据@bjauth的答案,我编写了以下函数

"Return the aesthetics produced by a Gadfly Statistic object."
function process_statistic(statistic::Gadfly.StatisticElement,
                           input_aesthetics::Dict{Symbol,<:Any}
                           )

    # Check that enough statistics have been provided.
    required_aesthetics = Gadfly.input_aesthetics(statistic)
    for required_aesthetic in required_aesthetics
        if required_aesthetic ∉ keys(input_aesthetics) 
            error("Aesthetic $(required_aesthetic) is required")
        end
    end

    # Create the aes object, which contains the statistics.
    aes = Gadfly.Aesthetics()
    [setfield!(aes, key, value) for (key, value) in input_aesthetics]

    # These need to be passed to the apply_statistic() function. I do
    # not understand them, and the below code might need to be edited
    # for this function to work in some cases.
    scales = Dict{Symbol, Gadfly.ScaleElement}()
    coord  = Gadfly.Coord.Cartesian()

    # This function edits the aes object, filling it with the desired aesthetics.
    Gadfly.Stat.apply_statistic(statistic, scales, coord, aes)

    # Return the produced aesthetics in a dictionary.
    outputs = Gadfly.output_aesthetics(statistic)
    return Dict(output => getfield(aes, output) for output in outputs)

end

谢谢你,亚瑟。我提出了自己的答案,作为一个更具程序性的建议。
process_statistic(Stat.histogram(), Dict(:x => rand(100)))