Title: | Automatic Cognostic Summaries |
---|---|
Description: | Automatically calculates cognostic groups for plot objects and list column plot objects. Results are returned in a nested data frame. |
Authors: | Barret Schloerke [aut], Ryan Hafen [ths, cre] |
Maintainer: | Ryan Hafen <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.4 |
Built: | 2024-11-03 03:50:23 UTC |
Source: | https://github.com/schloerke/autocogs |
Add a new cognostic to be used when calculating automatic cognostics.
add_cog_group(name, fields, description = NA, fn, ...)
add_cog_group(name, fields, description = NA, fn, ...)
name |
Name of cognostic group |
fields |
|
description |
Description of cognostic group |
fn |
function to calculate a cognostic group. May return a named list or a single row tibble. Each value of the return data should be the output of |
... |
ignored |
Add a new set of cognostic groups for a given plot layer. If the plot layer is found, the corresponding cognostic groups will be calculated.
add_layer_cogs(name, description, cog_groups, kind = "ggplot", ...)
add_layer_cogs(name, description, cog_groups, kind = "ggplot", ...)
name |
Name of plot layer. This should match the output of the |
description |
Description of cognostic group |
cog_groups |
A |
kind |
String value that will match the output of |
... |
ignored |
Calculate an auto cognostic function given a name
autocog(.name, ..., .fn_only = FALSE)
autocog(.name, ..., .fn_only = FALSE)
.name |
name of a known cognostic |
... |
arguments passed onto the found function |
.fn_only |
boolean that determines if the function should be returned |
autocog("univariate_continuous", iris$Sepal.Length) fn <- autocog("univariate_continuous", .fn_only = TRUE) fn(iris$Sepal.Length)
autocog("univariate_continuous", iris$Sepal.Length) fn <- autocog("univariate_continuous", .fn_only = TRUE) fn(iris$Sepal.Length)
These set of functions comprise the default cognostic groups. Each function produces it's own cognostic information given the required pieces of data.
The functions' print method will display the description. autocog_*
functions will take the known_cog_groups()
functions and format the output into a single row tibble. Any new known cognostic group function, NAME, will create a function called autocog_NAME, which may be called.
Default Cognostic Group Functions:
autocog_bivariate_continuous
autocog_bivariate_counts
autocog_bivariate_step
autocog_boxplot
autocog_density_2d_continuous
autocog_density_continuous
autocog_grouped_counts
autocog_grouped_testing
autocog_hex_counts
autocog_histogram_counts
autocog_linear_model
autocog_loess_model
autocog_pairwise_counts
autocog_quantile_quantile
autocog_scagnostics
autocog_smooth_line
autocog_square_counts
autocog_univariate_continuous
autocog_univariate_counts
autocog_univariate_discrete
x |
data that should appear on an x axis |
y |
data that should appear on an y axis |
... |
ignored |
direction |
step direction. Defaults to |
na.rm |
should |
h , n , bins , binwidth , clusters , bw , adjust , kernel , trim , group , groups , center , boundary , closed , pad , breaks , weights , formula , method_args , span , distribution , dparams , method , se , fullrange , xseq , level , origin , drop
|
parameters usually set by corresponding "geoms" to be used within ggplot2 Stat* methods |
autocog_bivariate_continuous autocog_bivariate_continuous(iris$Sepal.Length, iris$Sepal.Width)
autocog_bivariate_continuous autocog_bivariate_continuous(iris$Sepal.Length, iris$Sepal.Width)
Add a description to a cognostic (subset metric)
cog_desc(x, desc = NULL)
cog_desc(x, desc = NULL)
x |
univariate scalar |
desc |
description of |
cog_desc(mean(1:10), "mean of 10 numbers")
cog_desc(mean(1:10), "mean of 10 numbers")
Make a cog group data frame to be passed into add_layer_cogs
cog_group(...)
cog_group(...)
... |
sets of three values to fill in 'cog_group', 'cols', and 'name' |
cog_group( "univariate_discrete", "x", "_x", "univariate_counts", "x", "_n" ) cog_group( "univariate_continuous", "x", "_x", "univariate_continuous", "y", "_y", "bivariate_continuous", c("x", "y"), "_bivar", "scagnostics", c("x", "y"), "_scagnostic", "bivariate_counts", c("x", "y"), "_n" )
cog_group( "univariate_discrete", "x", "_x", "univariate_counts", "x", "_n" ) cog_group( "univariate_continuous", "x", "_x", "univariate_continuous", "y", "_y", "bivariate_continuous", c("x", "y"), "_bivar", "scagnostics", c("x", "y"), "_scagnostic", "bivariate_counts", c("x", "y"), "_n" )
Cognostic Specification
cog_spec( bivariate_continuous = TRUE, bivariate_counts = TRUE, bivariate_step = TRUE, boxplot = TRUE, density_2d_continuous = TRUE, density_continuous = TRUE, grouped_counts = TRUE, grouped_testing = TRUE, hex_counts = TRUE, histogram_counts = TRUE, linear_model = TRUE, loess_model = TRUE, pairwise_counts = TRUE, quantile_quantile = TRUE, scagnostics = TRUE, smooth_line = TRUE, square_counts = TRUE, univariate_continuous = TRUE, univariate_counts = TRUE, univariate_discrete = TRUE, ..., .keep_layer = TRUE ) as_cog_specs(p, specs)
cog_spec( bivariate_continuous = TRUE, bivariate_counts = TRUE, bivariate_step = TRUE, boxplot = TRUE, density_2d_continuous = TRUE, density_continuous = TRUE, grouped_counts = TRUE, grouped_testing = TRUE, hex_counts = TRUE, histogram_counts = TRUE, linear_model = TRUE, loess_model = TRUE, pairwise_counts = TRUE, quantile_quantile = TRUE, scagnostics = TRUE, smooth_line = TRUE, square_counts = TRUE, univariate_continuous = TRUE, univariate_counts = TRUE, univariate_discrete = TRUE, ..., .keep_layer = TRUE ) as_cog_specs(p, specs)
bivariate_continuous , bivariate_counts , bivariate_step , boxplot , density_2d_continuous , density_continuous , grouped_counts , grouped_testing , hex_counts , histogram_counts , linear_model , loess_model , pairwise_counts , quantile_quantile , scagnostics , smooth_line , square_counts , univariate_continuous , univariate_counts , univariate_discrete
|
names of cognostic groups to calculate. The boolean value (TRUE) supplied to each argument determines if the value should be displayed if possible or removed if possible. |
... |
ignored. Will cause error if any are supplied |
.keep_layer |
boolean (TRUE) that determines if the layer should be kept at all |
p |
plot object in question |
specs |
list of cog_spec outputs for each layer of the plot object |
cognostic specification that determines which cogs are added or removed if possible
# example cog specifications # display like normal cog_spec(); TRUE # remove scagnostics cog_spec(scagnostics = FALSE) # remove layer cog_spec(.keep_layer = FALSE); FALSE # set up data p <- ggplot2::qplot(Sepal.Length, Sepal.Width, data = iris, geom = c("point", "smooth")) dt <- tibble::tibble(panel = list(p)) # compute cognostics like normal add_panel_cogs(dt) # do not compute scagnostics for geom_point cognostics # compute geom_smooth cognostics add_panel_cogs(dt, spec = list(cog_spec(scagnostics = FALSE), TRUE)) # do not compute scagnostics for geom_point cognostics # do not compute geom_smooth cognostics add_panel_cogs(dt, spec = list(cog_spec(scagnostics = FALSE), FALSE))
# example cog specifications # display like normal cog_spec(); TRUE # remove scagnostics cog_spec(scagnostics = FALSE) # remove layer cog_spec(.keep_layer = FALSE); FALSE # set up data p <- ggplot2::qplot(Sepal.Length, Sepal.Width, data = iris, geom = c("point", "smooth")) dt <- tibble::tibble(panel = list(p)) # compute cognostics like normal add_panel_cogs(dt) # do not compute scagnostics for geom_point cognostics # compute geom_smooth cognostics add_panel_cogs(dt, spec = list(cog_spec(scagnostics = FALSE), TRUE)) # do not compute scagnostics for geom_point cognostics # do not compute geom_smooth cognostics add_panel_cogs(dt, spec = list(cog_spec(scagnostics = FALSE), FALSE))
Field Type Information
field_info( dimension = c("x", "y", "z", "group", "any"), type = c("continuous", "discrete", "date", "any") )
field_info( dimension = c("x", "y", "z", "group", "any"), type = c("continuous", "discrete", "date", "any") )
dimension |
field name. Use one of the listed options provided |
type |
field type. Use one of the listed options provided |
To add more cognostic groups, please see add_cog_group()
known_cog_groups()
known_cog_groups()
known_cog_groups()
known_cog_groups()
Display all layer cognostic information to be paired with information from known_cog_groups()
.
known_layer_cogs()
known_layer_cogs()
known_layer_cogs()
known_layer_cogs()
Retrieves the number of layers in a given plot
layer_count(p) ## Default S3 method: layer_count(p) ## S3 method for class 'ggplot' layer_count(p)
layer_count(p) ## Default S3 method: layer_count(p) ## S3 method for class 'ggplot' layer_count(p)
p |
plot object |
number
library(ggplot2) p <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point() layer_count(p) # 1 layer_count(p + geom_smooth(method = "lm") + geom_density_2d()) # 3
library(ggplot2) p <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point() layer_count(p) # 1 layer_count(p + geom_smooth(method = "lm") + geom_density_2d()) # 3
Data List
layer_info(p, keep = TRUE, ...) ## Default S3 method: layer_info(p, keep = TRUE, ...) ## S3 method for class 'ggplot' layer_info(p, keep = TRUE, ...)
layer_info(p, keep = TRUE, ...) ## Default S3 method: layer_info(p, keep = TRUE, ...) ## S3 method for class 'ggplot' layer_info(p, keep = TRUE, ...)
p |
plot object |
keep |
boolean vector (size = 1 or length(plot$layers)). Determines if that layer should have cognostics calculated |
... |
parameters passed on to corresponding |
require(ggplot2) p <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point(data = mpg, mapping = aes(cty, hwy)) layer_info(p)
require(ggplot2) p <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point(data = mpg, mapping = aes(cty, hwy)) layer_info(p)
Return or concatenate panel cognostics. For each panel (plot) in the panel column, cognostics will be calculated for each panel. The result will be returned in a nested tibble
.
panel_cogs(dt, panel_col = "panel", ...) add_panel_cogs(dt, panel_col = "panel", ...)
panel_cogs(dt, panel_col = "panel", ...) add_panel_cogs(dt, panel_col = "panel", ...)
dt |
data to be used |
panel_col |
panel column to be used in |
... |
parameters passed to |
First class of the plot object. Exception is ggplot2 as many objects are of class 'gg'
plot_class(p) ## Default S3 method: plot_class(p) ## S3 method for class 'gg' plot_class(p) ## S3 method for class 'ggplot' plot_class(p)
plot_class(p) ## Default S3 method: plot_class(p) ## S3 method for class 'gg' plot_class(p) ## S3 method for class 'ggplot' plot_class(p)
p |
plot object to retrieve class from |
library(ggplot2) p <- qplot(Sepal.Length, Sepal.Width, data = iris) plot_class(p)
library(ggplot2) p <- qplot(Sepal.Length, Sepal.Width, data = iris) plot_class(p)