queryverse / VegaLite.jl

Julia bindings to Vega-Lite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

problem try to juxtapose two plots

ericqu opened this issue · comments

I am trying to have two plots one next to each other (like in the example at the bottom of this page).

I am using VegaLite v2.6.0.
Here is a reproducible code:

The first plot:

resid = [2.1948046177180736, -1.1306726705053904, 0.8135905418836913, -1.064679425301394, -1.9014648038705442, 1.125692244785192, 0.3697074698040863, 0.4061480703042779, 0.5065088140192389, -1.2042397867136634]
pred = [7.305195382281926, 12.350672670505391, 9.24640945811631, 8.464679425301394, 6.0514648038705445, 9.684307755214808, 6.260292530195914, 11.443851929695722, 6.033491185980761, 5.894239786713664]
res = DataFrame(residuals = resid, predicted = pred)

p = select(res, [:residuals, :predicted]) |> 
    @vlplot(title = "Residuals", width = 400, height = 400,
        x = {axis = {grid = false}, scale = {zero = false}},
        y = {axis = {grid = false} }) +
    @vlplot(mark= :point, x = :predicted, y = :residuals ) +
    @vlplot(mark = {:rule, color = :darkgrey}, y = {datum = 0})

asset_issue_resi_001
The second:

mp = select(res, [:residuals, :predicted]) |> @vlplot(
    width=100,
    height=400,
    mark= {:area, orient="horizontal"},
    transform=[{density=:residuals, bandwidth=0.4} ],
    x={"density:q", title=nothing, axis = {grid = false}, scale = {zero = false}},
    y={"value:q", title=nothing, axis = nothing }
)

asset_issue_resi_002

And I got the display I expected.

But when I put them together with:

tp = @vlplot(bounds=:flush, spacing=15) + [p mp]

asset_issue_resi_003

Then the axis on the plot the most on the left changes unexpectedly.

What should I do? or how should I proceed to find the cause of the problem?

Try specifying the scale type "quantitative" for the variables in the first plot? Looks like it is being converted to categorical / ordinal. E.g.

y={field="b", type="quantitative"}

Link: https://www.queryverse.org/VegaLite.jl/stable/userguide/vlspec/#

Excellent! this does solve the issue. 👍

If you could work your magic on my other issue #406 , it would be awesome.