Interactive plot with Vegalite


Is anyone familiar with using Vegalite from the REPL to produce interactive plots (to zoom in/out at a minimum)?

I understand this works in Jupyter notebooks, but I want to avoid notebooks and work directly in the terminal command line. By the way, my platform is Windows 10.

I managed to display plots in web browsers or in the Electron, but they are not interactive in any way.



Did you actually create an interactive plot along the description in They should work in the browser, ElectronDisplay and VS Code plot pane. Not entirely sure about Juno.



Yes, I tried to do that. I followed the example from the documentation:

properties = loadjson("full_alu_cyl-nr=15xnL=60-neigvs=1000.json")

f = convert.(Float64, properties["frequencies"])
DataFrame(serial = 1:length(f), frequency = f)  |> @vlplot(
    selection = {
        brush = {
          typ = "interval"
)  |> display 

I do get to drag out a rectangle, but no zooming occurs.



I think now that the incantation should be like this:

DataFrame(serial = 1:length(f), frequency = f)  |> @vlplot(
    mark={:point, color=:red, clip = true},
    selection = {
        grid = {
          typ = "interval", bind = "scales"
    x =  {
      field = :serial
    y = {
      field = :frequency
)  |> display

The zoom actually works (even though it requires the use of a mouse wheel and only allows isotropic zoom).



I at some point added an interactive function here. It is not exported and I’m not sure it works, and it is not part of the official API, so we might remove it at some point. But, with all of these caveats out of the way, you could try:

data |> @vlplot(bla bla) |> VegaLite.interactive() |> display

And it might do something…



Thanks, I will check it out.



The interactivity was working with a single @vlplot, but adding together plots made the interactivity not work again. This is what I tried:

    DataFrame(sn = 1:length(fullfrequencies), frequency = fullfrequencies, approxfrequency = approxfrequencies) |> 
	@vlplot(height = 450, width = 450) +
	@vlplot(mark={:point, size=2, color=:red, clip = true},
		    x = :sn,    y = :frequency, 
		    tooltip = {field = :frequency, typ = "quantitative"}
		) + 
	@vlplot(mark={:point, size=2, color=:blue, clip = true},
		    x = :sn,    y = :approxfrequency, 
		    tooltip = {field = :approxfrequency, typ = "quantitative"}
		)  |> VegaLite.interactive() |> 

Any ideas would be much appreciated.



Not sure, to be honest… I think your best bet is to open the vega-lite spec in the online vega editor (there should be a button in the browser view for that) and then play around with the spec there until it does what you want it to do. I suspect that the way we add interactivity currently with VegaLite.interactive() doesn’t mesh with composite specs. There is a reason why I don’t export that function :wink:



The spec produced with VegaLite.interactive() actually works with other VegaLite examples (I could get it to work in the editor). Somehow the problem must be with the data. I have three columns in the data frame, and that should produce two curves. Like so:

The figure is obviously correctly produced, but somehow the form of the data makes the interactivity not work. Can you think of some alternative presentation of the data?
Many thanks.