I am trying to create a time series in vegalite. I started with values at a given end date as points and a loess fit on that as line.
But I wanted to change from points to lines of x: start and end date at the given y: value and a fit on the center of start and end date.
I computed the “mid-date” as the point of time between start and end date. The start_date is first date, that shall be included.
defmodule PollGraphs do
def create_graph(data_source, title, col, start_date) do
Vl.new(width: 500, height: 300, title: title)
|> Vl.data_from_values(DF.filter(data_source, mid_date > ^start_date),
only: ["end_date", "start_date", "mid_date", col, "category"]
)
|> Vl.layers([
Vl.new()
|> Vl.mark(:bar, opacity: 0.5)
|> Vl.encode_field(:x, "start_date", type: :temporal, title: "poll end date")
|> Vl.encode_field(:x2, "end_date")
|> Vl.encode_field(:y, col, type: :quantitative, title: "percentage", scale: [domain: [param: [35, 45]]])
|> Vl.encode_field(:color, "category", type: :nominal),
Vl.new()
|> Vl.mark(:line, color: "firebrick", opacity: 0.5)
|> Vl.transform(loess: col, on: "start_date", bandwidth: 0.5)
|> Vl.encode_field(:x, "start_date", type: :temporal, title: "poll end date")
|> Vl.encode_field(:y, col, type: :quantitative, title: "percentage")
])
end
I have three problems.
- how can I get round corners working?
- the scale in y axis is twice the size as when I used, :point and can not change it.
- I can’t get loess fit working on “mid_date”