I have a dataset with continuous values and would like to plot those values together with their running averages in a layered plot. Works well in this simple case:
using Random, DataFrames, Queryverse
Random.seed!(1234)
df = DataFrame(index=1:100, value=rand(100))
df |> @vlplot(transform=[{frame= [-15, 15], window=[{op=:mean, field=:value, as=:avg_value}]}]) +
@vlplot(
mark={:line, strokeWidth=2, opacity=0.5},
x="index:q",
y="value:q"
) +
@vlplot(
mark={:line, strokeWidth=3},
x="index:q",
y="avg_value:q"
)
However, if I now would like to stratify the plot according to a categorical variable, the following fails:
df[!, :category] .= rand(1:2, 100)
df |> @vlplot(facet={column={field="category", typ="nominal"}}) +
(
@vlplot() +
@vlplot(
mark=:line,
x="index:q",
y="value:q",
) + @vlplot(
mark={:line, strokeWidth=3},
transform=[{frame= [-15, 15], window=[{op=:mean, field=:value, as=:avg_value}]}],
x="index:q",
y={field=:avg_value, typ=:quantitative, aggregate=:mean},
color={value=:red}
)
)
[…]
Putting the transform
statement in other places (for instance the initial @vlplot()
's) unfortunately results in the same error. This simplified, transformation-less version however works:
df |>
@vlplot(facet={column={field="category", typ="nominal"}}) +
(
@vlplot() +
@vlplot(
mark=:line,
x="index:q",
y="value:q",
) + @vlplot(
mark={:rule, strokeWidth=3},
y={field=:value, typ=:quantitative, aggregate=:mean},
color={value=:red}
)
)
Any idea what I’m doing wrong?