Get startedGet started for free

Cognostics

1. Cognostics

In the previous exercise, you may have noticed that a cognostic was automatically computed for the variable min_volume in addition to summary statistics for each variable in the nested data frame, data. By adding additional columns to our data frame, we can add our own custom cognostics just as we did with ggplot2, but here it is more intuitive.

2. Variables = cognostics

In the by_symbol dataset that we created in the previous video, we added a new variable last_close. You may have noticed that this variable showed up as a cognostic in the resulting display. It turns out that adding custom cognostics to Trelliscope displays through the tidyverse approach is as simple as adding new variables to the data frame.

3. Adding cognostics to the stock data

We have a set of metadata about each stock called stock_meta. This has different pieces of information about each stock, including the stock's market capitalization, the sector, and industry the stock is classified under. We can add these variables as cognostics to our display by simply joining the dataset to our by_symbol dataset, using dplyr's left_join function. Once we create a new trelliscope display with this data, these variables will automatically be available as cognostics.

4. Cognostics as nested data frames

It can often be convenient to compute on nested data to specify multiple cognostics at once. For example, suppose we wish to compute the minimum and maximum volume for each stock. We can use map() to apply a function to each nested data frame that computes these values and returns a single-row nested data frame for each stock. Here we store this set of nested data frames as a new variable volume_stats. To verify that the new volume_stats variable does indeed contain a single-row data frame of cognostics, we can inspect the entry for the first stock. When trelliscope finds a variable that contains single-row nested data frames, it will automatically turn these into cognostics as well.

5. Customizing cognostics

When creating cognostics, the TrelliscopeJS cog() wrapper function that we discussed in the previous chapter can also be used here to specify additional characteristics about cognostics that controls how they behave in the viewer. For example, if we want the company name to show up by default as a label in the display and we want to provide it a more useful description, we can recast it with the cog() wrapper.

6. Let's practice!

Now let's try some examples.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.