How to Get Data into Plotrb

Acknowledgment: This tutorial is based on Vega's documentation.

The very essence of a plot is the data behind it, and thus the information it is trying to convey. In this tutorial, I'm going to talk about how to get the data into Plotrb.

A Data class does not have many attributes (and it's not supposed to). The goal is to let you import the data as effortlessly as possible.


The name of the data set must be unique, so that you may reference it at other places of Plotrb.


Use an existing data set as source of the new data set.

You can pass in the name of the other data.


You can also pass in other data object directly.

some_data ='some_data')
new_data ='new_data').source(some_data)


The actual data can come from a url, for example a json file from some web service.



Similar to url, the data may also come from a local file, for example a csv file in another directory.



The data do not necessarily have to come from external sources. Instead of referencing the data source, you can also pass in the actual data values directly to Plotrb.

Currently, Plotrb supports several value types. You can pass in the values as an array.


You can also pass in a hash.

data.values(foo: 1, bar: 2, baz: 3)

Or you can pass in JSON as string directly.

data.values('{"foo":1, "bar":{"baz":2}}')


Specify the transforms to be performed on the data.


As of now, Plotrb supports five types of data formats, namely csv, tsv, json, topojson, and treejson.

To assign specific attribtues for a format, you have to define the format first.


You can also use the following grammar.


(Manipulating attributes for a format must be done inside a block, as you will see in the following examples.)

comments powered by Disqus