Engee 文档

组图

二氧化碳数据集的内容解释见 此处

import RDatasets: dataset
using GenieFramework, DataFrames, PlotlyBase
@genietools

const data = dataset("datasets", "CO2")

@app begin
    @out trace =  scatter(data, x=:Conc, y=:Uptake, group=:Treatment, mode="markers")
    @out layout = PlotlyBase.Layout(;xaxis_title="Concentration", yaxis_title="Uptake", legend_title_text = "Treatment")
end

ui() = GenieFramework.plot(:trace, layout = :layout)
@page("/",ui)

设置自定义颜色和标记

在绘制 DataFrame 中的内容时,scatter 和其他跟踪生成器接受函数作为参数,并将其应用于 DataFrame。有关详细信息,请参阅`PlotlyBase.GenericTrace` 的帮助。当`group` 参数存在时,函数将应用于每个子 DataFRame。

import RDatasets: dataset
using GenieFramework, DataFrames, PlotlyBase
@genietools

const data = dataset("datasets", "CO2")

# function to set the color of each point according to the Treatment column
color_dict = Dict("nonchilled" => "red", "chilled" => "blue")
plot_color(x) = getindex.(Ref(color_dict), x.Treatment)
# function to set the marker of each point according to the Type column
symbol_dict = Dict("Quebec" => "cross", "Mississippi" => "square")
plot_marker(x) = attr(symbol=getindex.(Ref(symbol_dict), x.Type), size=8)

@app begin
    @out trace =  PlotlyBase.scatter(data, x=:Conc, y=:Uptake, group=[:Treatment, :Type], mode="markers", color=plot_color,  marker=plot_marker)
    @out layout = PlotlyBase.Layout(;xaxis_title="Concentration", yaxis_title="Uptake", legend_title_text = "Treatment, Type")
end

ui() = GenieFramework.plot(:trace, layout = :layout)
@page("/",ui)