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:
invisible(self), enabling a fluid workflowplot_* methods detect prior statistical tests and add
results as plot titles$command and $resultfun parameter lets you modify self$data
on the flylitedown::reactor(warning = FALSE)
library(easybio)
library(data.table)
# Example data: airquality, focusing on May and June
air <- subset(airquality, Month %in% c(5, 6))
setDT(air)
Create an Artist instance and start plotting.
a <- Artist$new(data = air)
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]> |
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)
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)
funThe 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.
All plot methods follow the same interface and support chaining.
# Summarise data for dumbbell
air[, mean_temp := mean(Temp), by = Month]
a$plot_dumbbell(x = Month, y = mean_temp, col = factor(Month))
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)])
a2$plot_bubble(x = Month, y = Day, size = N, col = N)
# 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)
a3$plot_barchart_divergence(group = group, y = value)
a3$plot_lollipop(x = group, y = value)
a$plot_contour(x = Wind, y = Temp)
a$plot_scatter_ellipses(x = Wind, y = Temp, col = factor(Month))
month_counts <- air[, .N, by = Month]
a4 <- Artist$new(data = month_counts)
a4$plot_donut(x = Month, y = N, fill = factor(Month))
a4$plot_pie(y = N, fill = factor(Month))
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
#>
The Artist class turns exploratory data analysis into a structured, reproducible
workflow. You can:
plot_scatter, plot_box, plot_dumbbell, etc.test_wilcox, test_tget_all_result() gives you the complete historyThis makes it ideal for quick data inspection before committing to a formal analysis pipeline.