In this Session…

Before you begin…

  • Using Transforms:

    • f(x) and Link to reformat and reorganize data.

    • Aggregate to enumerate and/or evaluate nodes or edges.

    • Merge to merge nodes or edges.

To follow along, download the files:

HowTo_05_START.graphxr

and http://kineviz.com/s/GXR_QSG.zip


Slide

1

How To GraphXR 5. Aggregate and Merge

2

Before You Begin…

Ideally, you’ll have worked through Module 4. Link and Filter. If you’re starting here, and you want to follow along, you’ll need to:

  • Log in to GraphXR, create a Project, and open its graph space. 

  • Download the file http://kineviz.com/s/GXR_QSG.zip, which contains the Game of Thrones data we’ll use in our tutorials.

  • Drag and drop the file 05_START.graphxr onto the space.

3

So far, we’ve extracted a House category from the Characters.csv data, created a belongs_to relationship with Character nodes, and a spoke relationship between Characters and the Lines they spoke. 

4

Now drag and drop Episodes.csv onto the graph space. Episodes, our new category, contains the titles, descriptions, air dates, episode numbers, season numbers, and viewership for each episode. We want to link corresponding lines and episodes.

5

We have a little problem, though. In Lines, season and episode number are combined into the single string seasonEpisode. In Episodes, they occupy separate properties.

6

To fix this, we’ll use the Transform panel => f(x) tab. The f(x) transform lets us perform javascript formulas on a single category or relationship. Several presets are included, but for this we’ll need to enter a custom formula.

7

Select Episodes and episodeNumber. Input

“(propVal,props) => 'S'+props.seasonNumber+'E'+props.episodeNumber”

as the custom formula and seasonEpisode as the new property name. 

Note the example result automatically calculated under the New Property Name

8

Click Run and the results appear below.

9

Now that we have matching values, we can link up Episodes and Lines in the Link tab using the seasonEpisode property.

10

Next, let’s calculate the total number of lines per episode. Go to the Transform panel => Aggregate tab (after taking a Snapshot for good measure!). The Aggregate transform retrieves properties from a selected node’s connected edges or neighbor nodes, applies a formula to those properties, then writes the results back to the selected node.

11

Here we’re starting with our Episodes and following spoken_on to find lineCount values. We can use the sum preset to add those values together and then write the result back to Episodes nodes as a new value called totalLines.

12

And here we’ll perform a count of Episodes spoken_on connections and write the result back to Episodes nodes as totalCharacters.

13

Next, we can merge all the Lines for each episode. But first! Let’s create another Snapshot. Note that at any time, you can download all your snapshots as a single .ZIP. Now, on to merging.

14

Merge combines nodes of a single category or the edges of a single relationship based on a property value. Here, we’ve combined all the lines spoken on a single episode into a single node based on seasonEpisode

15

This simplifies the graph considerably, but we can take it a step further. In Module 6. Shortcut, we’ll return to the Snapshot we created before merging, and reduce the graph even more.

Next Steps…