【发布时间】:2022-11-03 07:01:16
【问题描述】:
我有一个汇总价格与用户数量的数据表。当我想显示覆盖有移动平均线的散点图时,我使用以下 Julia 函数:
function log_scatter(df::DataFrame; smooth=2, title="Price by Number of Users")
sort(select(df, [:Price, :Users]), :Users) |>
@vlplot(width=640,height=512, title=title) +
@vlplot(mark={:point, opacity=0.5}, x={field=:Users, scale={type="log"},title="Users"}, y={:Price,title="Price per User"}) +
@vlplot(transform=[
{ groupby=[:Users], aggregate=[{ op=:mean, field=:Price, as="AvgPrice" }] },
{ frame=[-smooth,smooth], window=[{ field="AvgPrice", op=:mean, as="rolling" }] }
],
mark={:line,size=2,color="red"}, x={:Users, title="Users"}, y={"rolling:q", title="Average"})
end
不幸的是,当我想对分组做同样的事情时,我无法显示移动平均线
function log_scatter_and(df::DataFrame, other; smooth=2, title="Price by Number of Users")
otherSym=Symbol(other)
prices = price_and(df, other)
sort(select(prices, [:Price, :Users, otherSym]), :Users) |>
@vlplot(width=640,height=512, title=title) +
@vlplot(mark={:point, opacity=0.5}, color=otherSym, x={field=:Users, scale={type="log"},title="Users"}, y={:Price,title="Price per User"}) +
@vlplot(transform=[
{ groupby=[:Users, otherSym], aggregate=[{ op=:mean, field=:Price, as="AvgPrice" }] },
{ frame=[-smooth,smooth], window=[{ field="AvgPrice", op=:mean, as="rolling" }] }
],
mark={:line,size=2,color=otherSym}, x={:Users, title="Users"}, y={"rolling:q", title="Average"})
end
我希望显示滚动平均线以及散点图
【问题讨论】: