## Lyra.jl

Julia wrapper for the Lyra Visualization Design Environment
Author queryverse
Popularity
2 Stars
Updated Last
2 Years Ago
Started In
March 2020

# Lyra

## Overview

This package provides Julia integration for the Lyra Visualization Design Environment.

NOTE THAT THIS PACKAGE CURRENTLY USES A VERY EXPERIMENTAL AND UNSTABLE BUILD OF LYRA AND IS NOT READY FOR REAL USE.

## Getting Started

Lyra.jl is an interactive environment that enables custom visualization design without writing any code.

You can install the package at the Pkg REPL-mode with:

`pkg> add https://github.com/queryverse/Lyra.jl`

## Visualizing data

You create a new Lyra window by calling `LyraWindow`:

```using Lyra

l = LyraWindow()```

By itself this is not very useful, the next step is to load some data into Lyra. Lets assume your data is in a `DataFrame`:

```using DataFrames, Lyra

data = DataFrame(a=rand(100), b=randn(100))

l = LyraWindow(data)```

You can also use the pipe to load data into Lyra:

```using DataFrames, Lyra

data = DataFrame(a=rand(100), b=randn(100))

l = data |> LyraWindow()```

With a more interesting data source

```using VegaDatasets, Lyra

l = dataset("cars") |> LyraWindow()```

You can load any source that implements the TableTraits.jl interface into Lyra, i.e. not just `DataFrame`s. For example, you can load some data from a CSV file with CSVFiles.jl, filter them with Query.jl and then visualize the result with Lyra:

```using FileIO, CSVFiles, Query, Lyra

l = load("data.csv") |> @filter(_.age>30) |> LyraWindow()```

In this example the data is streamed directly into Lyra and at no point is any `DataFrame` allocated.

The datasets we added so far were named with the default name `dataset`. You can also give the dataset your own name, by passing a `Pair` instead of the raw data to `LyraWindow`:

```using VegaDatasets, Lyra

l = LyraWindow(:cars=>dataset("cars"))```

You can also make multiple datasets available to the Lyra environment. In that case you need to give each a unique name. The following example passes both the `cars` and `movies` dataset to Lyra:

```using VegaDatasets, Lyra

l = LyraWindow(:cars=>dataset("cars"), :movies=>dataset("movies"))```

You can use the `add!` function to add additional datasets to an existing Lyra window:

```using VegaDatasets, Lyra

l = LyraWindow()

## Extracting plots

You can also access a plot that you have created in the Lyra UI from Julia, for example to save the plot to disc.

You can access the currently active plot in a given Lyra window `l` with the brackets syntax:

```using VegaDatasets, Lyra, VegaLite

l = dataset("cars") |> LyraWindow()

plot1 = l[]```

At this point `plot1` will hold a standard VegaLite.jl plot object. You can use the normal VegaLite.jl functions to display such a plot, or save it to disc:

```display(plot1)

plot1 |> save("figure1.pdf")```

A useful pattern here is to save the plot as a Vega JSON file to disc, without the data:

```using VegaDatasets, Lyra, VegaLite

l = dataset("cars") |> LyraWindow()

# Now create the plot in the UI

l[] |> save("figure1.vega")```

At a later point you can then load this plot specification again, but pipe new data into it [TODO Make sure this works]:

```using VegaLite, VegaDatasets
{"ft_lang_label":"__label__en","ft_lang_prob":0.70022374,"math_prob":0.77168936,"size":3021,"snap":"2022-40-2023-06","text_gpt3_token_len":775,"char_repetition_ratio":0.1600928,"word_repetition_ratio":0.05263158,"special_character_ratio":0.23700762,"punctuation_ratio":0.12435233,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97640103,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-10-04T16:27:02Z\",\"WARC-Record-ID\":\"<urn:uuid:a5afcac9-cd5f-42f9-af4a-2c3e37ffdcf1>\",\"Content-Length\":\"109357\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:53c64089-64a3-4ddc-a5fc-e3e0e77bbc5a>\",\"WARC-Concurrent-To\":\"<urn:uuid:648a8f84-ad42-4101-a04b-facbb4240e67>\",\"WARC-IP-Address\":\"18.67.76.119\",\"WARC-Target-URI\":\"https://juliapackages.com/p/lyra\",\"WARC-Payload-Digest\":\"sha1:JSMCLIF75LLABT6PKYPHIUNMXO4TXSSR\",\"WARC-Block-Digest\":\"sha1:XMIC5R7NBR4AEGQJUOMZ4FECAFX4FAVB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030337516.13_warc_CC-MAIN-20221004152839-20221004182839-00673.warc.gz\"}"}