Begin article
This commit is contained in:
parent
938e938577
commit
17f8d0052d
48
www/src/visualizing_data_with_dust.md
Normal file
48
www/src/visualizing_data_with_dust.md
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# Visualizing Data with Dust
|
||||||
|
|
||||||
|
Dust is an experimental data-oriented programming language with powerful tools for working with structured data from external sources. Despite being a command line tool, dust is able to spin up GUI windows with plots, charts and graphs. This is done through the language itself and dust is distributed with this cross-platform capability built in. So it works in the REPL, in scripts or in ad-hoc commands through your shell.
|
||||||
|
|
||||||
|
To read more about dust, the project status and to learn the language, see the [README].
|
||||||
|
|
||||||
|
## Load Data
|
||||||
|
|
||||||
|
Loading data into a dust program or environment can be done by downloading it or loading it from a file. Let's use an example that downloads some raw data and saves it so we don't have to keep fetching the it.
|
||||||
|
|
||||||
|
```
|
||||||
|
raw_data = download "faithful.csv";
|
||||||
|
raw_data:write "faithful.csv";
|
||||||
|
```
|
||||||
|
|
||||||
|
Now we can load the data any time we like by reading the file.
|
||||||
|
|
||||||
|
```
|
||||||
|
raw_data = read("faithful.csv");
|
||||||
|
```
|
||||||
|
|
||||||
|
The second step is parsing the data into dust values. This is as easy as knowing the format of the data you just assigned to variable. In this case we'll use `from_csv` to turn `raw_data` into a table. The `from_json` and `from_toml` macros are also available as well as `to_csv`, etc.
|
||||||
|
|
||||||
|
## Explore
|
||||||
|
|
||||||
|
Printing the parsed data to the terminal will show that `from_csv` has created a table with three columns and 272 rows. Dust has pretty terminal output for tables but it's still a lot of scrolling and a wall of text does not make the data easy to understand. But if we want the data to fit in a bar graph, we will have to take an extra step to make it clear what the graph should display.
|
||||||
|
|
||||||
|
## Transform
|
||||||
|
|
||||||
|
The simplest bar graph just needs a list of values. The index of each value can provide the x axis position and a flaoting point value will provide the height. But that's not what were' working with. Our data is in a variable that is a table, not a list. If we want the rows of the table as list, we simple call `rows()`, which shows us the following output.
|
||||||
|
|
||||||
|
As you can see, each row is represented as another list. We want to *transform* each list into just the second value, which is a floating point.
|
||||||
|
|
||||||
|
```
|
||||||
|
table = from_csv(read("faithful.csv"));
|
||||||
|
rows = table:rows();
|
||||||
|
list = rows:transform('input.1');
|
||||||
|
```
|
||||||
|
|
||||||
|
The resulting list looks like this.
|
||||||
|
|
||||||
|
## Visualize
|
||||||
|
|
||||||
|
Now each item in the list can represent a single bar on the graph at they will be arranged by their position in the list. Just one last step to spin up our GUI!
|
||||||
|
|
||||||
|
```
|
||||||
|
bar_graph(list)
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user