cog: Cast Column as a Cognostic

Description Usage Arguments Details Value Examples

View source: R/cog.R

Description

Cast a column of a cognostics data frame as a cognostic object

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
cog(
  val = NULL,
  desc = "",
  group = "common",
  type = NULL,
  default_label = FALSE,
  default_active = TRUE,
  filterable = TRUE,
  sortable = TRUE,
  log = NULL
)

Arguments

val

a scalar value (numeric, character, date, etc.)

desc

a description for this cognostic value

group

optional categorization of the cognostic for organizational purposes in the viewer (currently not implemented in the viewer)

type

the desired type of cognostic you would like to compute (see details)

default_label

should this cognostic be used as a panel label in the viewer by default?

default_active

should this cognostic be active (available for sort / filter / sample) by default?

filterable

should this cognostic be filterable? Default is TRUE. It can be useful to set this to FALSE if the cognostic is categorical with many unique values and is only desired to be used as a panel label.

sortable

should this cognostic be sortable?

log

when being used in the viewer for visual univariate and bivariate filters, should the log be computed? Useful when the distribution of the cognostic is very long-tailed or has large outliers. Can either be a logical or a positive integer indicating the base.

Details

Different types of cognostics can be specified through the type argument that will affect how the user is able to interact with those cognostics in the viewer. This can usually be ignored because it will be inferred from the implicit data type of val. But there are special types of cognostics, such as geographic coordinates and relations (not implemented) that can be specified as well. Current possibilities for type are "key", "integer", "numeric", "factor", "date", "time", "href".

Value

object of class "cog"

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library(dplyr)
library(tidyr)
library(purrr)
library(ggplot2)
library(plotly)

mpg_cog <- mpg %>%
  nest(data = !one_of(c("manufacturer", "class"))) %>%
  mutate(
    cogs = map_cog(data, ~ tibble(
      mean_city_mpg = cog(mean(.$cty), desc = "Mean city mpg"),
      mean_hwy_mpg = cog(mean(.$hwy), desc = "Mean highway mpg"),
      most_common_drv = cog(tail(names(table(.$drv)), 1), desc = "Most common drive type")
    )),
    panel = map_plot(data, function(x) {
      plot_ly(data = x, x = ~cty, y = ~hwy,
        type = "scatter", mode = "markers") %>%
        layout(
          xaxis = list(range = c(9, 47)),
          yaxis = list(range = c(7, 37)))
    })
  )

trelliscope(mpg_cog, name = "city_vs_highway_mpg", nrow = 1, ncol = 2)

Example output

Attaching package:dplyrThe following objects are masked frompackage:stats:

    filter, lag

The following objects are masked frompackage:base:

    intersect, setdiff, setequal, union


Attaching package:plotlyThe following object is masked frompackage:ggplot2:

    last_plot

The following object is masked frompackage:stats:

    filter

The following object is masked frompackage:graphics:

    layout

Warning message:
`arrange_()` is deprecated as of dplyr 0.7.0.
Please use `arrange()` instead.
See vignette('programming') for more help
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated. 

trelliscopejs documentation built on Feb. 1, 2021, 9:05 a.m.