Exploratory Data Visualization with the Artist Class

2026-07-21

Introduction

The Artist class provides a fluent interface for rapid exploratory data visualization using ggplot2. It is designed to let you iterate quickly: plot, test, re-plot, and review your entire exploration history.

Key features:

Setup

litedown::reactor(warning = FALSE)

library(easybio)
library(data.table)
#> 
#> Attaching package: ‘data.table’
#> 
#> The following object is masked from ‘package:base’:
#> 
#>     %notin%
#> 
# Example data: airquality, focusing on May and June
air <- subset(airquality, Month %in% c(5, 6))
setDT(air)

Basic Usage

Create an Artist instance and start plotting.

a <- Artist$new(data = air)
#> Welcome to the amazing Artist's world, enjoy exploring your data in a new way!
a$plot_scatter(x = Wind, y = Temp)

The plot is displayed immediately and stored in a$result. You can retrieve the full history at any time:

a$get_all_result()[, .(command)]
command
<call[3]>

Statistical Tests and Auto-Annotation

This is the core design of Artist. When a plot_* method follows a test_* method, the statistical result is automatically added to the plot title.

a$plot_box(x = factor(Month), y = Ozone)

a$test_wilcox(formula = Ozone ~ Month)
a$plot_box(x = factor(Month), y = Ozone)

Notice how the second plot_box includes the previous test in its title — you immediately see the comparison context.

The same works with t.test:

a$plot_scatter(x = Wind, y = Temp)

a$test_t(formula = Temp ~ Month)
a$plot_scatter(x = Wind, y = Temp)

Method Chaining

All methods return the Artist object itself, so you can chain calls:

a$plot_scatter(x = Wind, y = Temp)$
  test_wilcox(formula = Ozone ~ Month)$
  plot_scatter(x = Wind, y = Temp)

Data Transformation with fun

The fun parameter applies a transformation to self$data before plotting. This is useful for derived variables:

a$plot_scatter(
  fun = \(x) x[, z := Wind * Temp],
  x = Wind,
  y = z
)

The transformation is applied in-place, so a$data now contains the z column.

Available Plot Types

All plot methods follow the same interface and support chaining.

Dumbbell Plot

# Summarise data for dumbbell
air[, mean_temp := mean(Temp), by = Month]
a$plot_dumbbell(x = Month, y = mean_temp, col = factor(Month))

Bubble Plot

air[, .N, by = .(Month, Day)]
Month Day N
5 1 1
5 2 1
5 3 1
5 4 1
5 5 1
6 26 1
6 27 1
6 28 1
6 29 1
6 30 1
a2 <- Artist$new(data = air[, .N, by = .(Month, Day)])
#> Welcome to the amazing Artist's world, enjoy exploring your data in a new way!
a2$plot_bubble(x = Month, y = Day, size = N, col = N)

Divergence Bar Chart

# Create some example data with positive and negative values
example <- data.table(
  group = letters[1:6],
  value = c(1.5, -0.8, 2.1, -1.2, 0.5, -0.3)
)
a3 <- Artist$new(data = example)
#> Welcome to the amazing Artist's world, enjoy exploring your data in a new way!
a3$plot_barchart_divergence(group = group, y = value)

Lollipop Plot

a3$plot_lollipop(x = group, y = value)

Contour Plot

a$plot_contour(x = Wind, y = Temp)

Scatter Plot with Ellipses

a$plot_scatter_ellipses(x = Wind, y = Temp, col = factor(Month))

Donut Plot

month_counts <- air[, .N, by = Month]
a4 <- Artist$new(data = month_counts)
#> Welcome to the amazing Artist's world, enjoy exploring your data in a new way!
a4$plot_donut(x = Month, y = N, fill = factor(Month))

Pie Chart

a4$plot_pie(y = N, fill = factor(Month))

Reviewing Your Exploration History

Every plot and test is recorded. Use get_all_result() to see the full log:

history <- a$get_all_result()
history
command result
<call[3]> ggplot2::ggplot
<call[3]> ggplot2::ggplot
<call[2]> <htest[7]>
<call[3]> ggplot2::ggplot
<call[3]> ggplot2::ggplot
<call[3]> ggplot2::ggplot
<call[4]> ggplot2::ggplot
<call[4]> ggplot2::ggplot
<call[3]> ggplot2::ggplot
<call[4]> ggplot2::ggplot
# The last plot
a$result[[length(a$result)]]

# The last statistical test result
for (res in a$result) {
  if (inherits(res, "htest")) print(res)
}
#> 
#> 	Wilcoxon rank sum exact test
#> 
#> data:  Ozone by Month
#> W = 82, p-value = 0.193
#> alternative hypothesis: true location shift is not equal to 0
#> 
#> 
#> 	Welch Two Sample t-test
#> 
#> data:  Temp by Month
#> t = -7.8672, df = 58.999, p-value = 9.181e-11
#> alternative hypothesis: true difference in means between group 5 and group 6 is not equal to 0
#> 95 percent confidence interval:
#>  -16.99842 -10.10481
#> sample estimates:
#> mean in group 5 mean in group 6 
#>        65.54839        79.10000 
#> 
#> 
#> 	Wilcoxon rank sum exact test
#> 
#> data:  Ozone by Month
#> W = 82, p-value = 0.193
#> alternative hypothesis: true location shift is not equal to 0
#> 

Summary

The Artist class turns exploratory data analysis into a structured, reproducible workflow. You can:

  1. Plotplot_scatter, plot_box, plot_dumbbell, etc.
  2. Testtest_wilcox, test_t
  3. Re-plot → same plot method now shows test context
  4. Reviewget_all_result() gives you the complete history

This makes it ideal for quick data inspection before committing to a formal analysis pipeline.