Artist: Visualization Artist for Custom Plots

ArtistR Documentation

Visualization Artist for Custom Plots

Description

The Artist class offers a suite of methods designed to create a variety of plots using ggplot2 for data exploration. Any methods prefixed with plot_ or test_ will log the command history along with their results, allowing you to review all outcomes later via the get_all_results() method. Notably, methods starting with plot_ will check if the result of the preceding command is of the htest class. If so, it will incorporate the previous command and its p-value as the title and subtitle, respectively. This class encompasses methods for crafting dumbbell plots, bubble plots, divergence bar charts, lollipop plots, contour plots, scatter plots with ellipses, donut plots, and pie charts. Each method is tailored to map data to specific visual aesthetics and to apply additional customizations as needed.

Value

The R6 class Artist.

Public fields

data

Stores the dataset used for plotting.

command

recode the command.

result

record the plot.

Methods

Public methods


Method new()

Initializes the Artist class with an optional dataset.

Usage
Artist$new(data = NULL)
Arguments
data

A data frame containing the dataset to be used for plotting. Default is NULL.

Returns

An instance of the Artist class.


Method get_all_result()

Get all history result

Usage
Artist$get_all_result()
Returns

a data.table object


Method test_wilcox()

Conduct wilcox.test

Usage
Artist$test_wilcox(formula, data = self$data, ...)
Arguments
formula

wilcox.test() formula arguments

data

A data frame containing the data to be plotted. Default is self$data.

...

Additional aesthetic mappings passed to wilcox.test().

Returns

A ggplot2 scatter plot.


Method test_t()

Conduct wilcox.test

Usage
Artist$test_t(formula, data = self$data, ...)
Arguments
formula

t.test() formula arguments

data

A data frame containing the data to be plotted. Default is self$data.

...

Additional aesthetic mappings passed to t.test().

Returns

A ggplot2 scatter plot.


Method plot_scatter()

Creates a scatter plot.

Usage
Artist$plot_scatter(
  data = self$data,
  fun = function(x) x,
  x,
  y,
  ...,
  add = private$is_htest()
)
Arguments
data

A data frame containing the data to be plotted. Default is self$data.

fun

function to process the self$data.

x

The column name for the x-axis.

y

The column name for the y-axis.

...

Additional aesthetic mappings passed to aes().

add

whether to add the test result.

Returns

A ggplot2 scatter plot.


Method plot_box()

Creates a box plot.

Usage
Artist$plot_box(
  data = self$data,
  fun = function(x) x,
  x,
  ...,
  add = private$is_htest()
)
Arguments
data

A data frame or tibble containing the data to be plotted. Default is self$data.

fun

function to process the self$data.

x

The column name for the x-axis.

...

Additional aesthetic mappings passed to aes().

add

whether to add the test result.

Returns

A ggplot2 box plot.


Method dumbbbell()

Create a dumbbell plot

This method generates a dumbbell plot using the provided data, mapping the specified columns to the x-axis, y-axis, and color aesthetic.

Usage
Artist$dumbbbell(data = self$data, x, y, col, ...)
Arguments
data

A data frame containing the data to be plotted.

x

The column in data to map to the x-axis.

y

The column in data to map to the y-axis.

col

The column in data to map to the color aesthetic.

...

Additional aesthetic mappings or other arguments passed to ggplot.

Returns

A ggplot object representing the dumbbell plot.


Method bubble()

Create a bubble plot

This method generates a bubble plot where points are mapped to the x and y axes, with their size and color representing additional variables.

Usage
Artist$bubble(data = self$data, x, y, size, col, ...)
Arguments
data

A data frame containing the data to be plotted.

x

The column in data to map to the x-axis.

y

The column in data to map to the y-axis.

size

The column in data to map to the size of the points.

col

The column in data to map to the color of the points.

...

Additional aesthetic mappings or other arguments passed to ggplot.

Returns

A ggplot object representing the bubble plot.


Method barchart_divergence()

Create a divergence bar chart

This method generates a divergence bar chart where bars are colored based on their positive or negative value.

Usage
Artist$barchart_divergence(data = self$data, group, y, fill, ...)
Arguments
data

A data frame containing the data to be plotted.

group

The column in data representing the grouping variable.

y

The column in data to map to the y-axis.

fill

The column in data to map to the fill color of the bars.

...

Additional aesthetic mappings or other arguments passed to ggplot.

Returns

A ggplot object representing the divergence bar chart.


Method lollipop()

Create a lollipop plot

This method generates a lollipop plot, where points are connected to a baseline by vertical segments, with customizable colors and labels.

Usage
Artist$lollipop(data = self$data, x, y, ...)
Arguments
data

A data frame containing the data to be plotted.

x

The column in data to map to the x-axis.

y

The column in data to map to the y-axis.

...

Additional aesthetic mappings or other arguments passed to ggplot.

Returns

A ggplot object representing the lollipop plot.


Method contour()

Create a contour plot

This method generates a contour plot that includes filled and outlined density contours, with data points overlaid.

Usage
Artist$contour(data = self$data, x, y, ...)
Arguments
data

A data frame containing the data to be plotted.

x

The column in data to map to the x-axis.

y

The column in data to map to the y-axis.

...

Additional aesthetic mappings or other arguments passed to ggplot.

Returns

A ggplot object representing the contour plot.


Method scatter_ellipses()

Create a scatter plot with ellipses

This method generates a scatter plot where data points are colored by group, with ellipses representing the confidence intervals for each group.

Usage
Artist$scatter_ellipses(data = self$data, x, y, col, ...)
Arguments
data

A data frame containing the data to be plotted.

x

The column in data to map to the x-axis.

y

The column in data to map to the y-axis.

col

The column in data to map to the color aesthetic.

...

Additional aesthetic mappings or other arguments passed to ggplot.

Returns

A ggplot object representing the scatter plot with ellipses.


Method donut()

Create a donut plot

This method generates a donut plot, which is a variation of a pie chart with a hole in the center. The sections of the donut represent the proportion of categories in the data.

Usage
Artist$donut(data = self$data, x, y, fill, ...)
Arguments
data

A data frame containing the data to be plotted.

x

The column in data to map to the x-axis.

y

The column in data to map to the y-axis.

fill

The column in data to map to the fill color of the sections.

...

Additional aesthetic mappings or other arguments passed to ggplot.

Returns

A ggplot object representing the donut plot.


Method pie()

Create a pie chart

This method generates a pie chart where sections represent the proportion of categories in the data.

Usage
Artist$pie(data = self$data, y, fill, ...)
Arguments
data

A data frame containing the data to be plotted.

y

The column in data to map to the y-axis.

fill

The column in data to map to the fill color of the sections.

...

Additional aesthetic mappings or other arguments passed to ggplot.

Returns

A ggplot object representing the pie chart.


Method clone()

The objects of this class are cloneable with this method.

Usage
Artist$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

library(data.table)
air <- subset(airquality, Month %in% c(5, 6))
setDT(air)
cying <- Artist$new(data = air)
cying$plot_scatter(x = Wind, y = Temp)
cying$test_wilcox(
  formula = Ozone ~ Month,
)
cying$plot_scatter(x = Wind, y = Temp)
cying$plot_scatter(f = \(x) x[, z := Wind * Temp], x = Wind, y = z)


easybio documentation built on Sept. 17, 2024, 1:08 a.m.