Artist | R Documentation |
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.
The R6
class Artist.
data
Stores the dataset used for plotting.
command
recode the command.
result
record the plot.
new()
Initializes the Artist class with an optional dataset.
Artist$new(data = NULL)
data
A data frame containing the dataset to be used for plotting. Default is NULL
.
An instance of the Artist class.
get_all_result()
Get all history result
Artist$get_all_result()
a data.table object
test_wilcox()
Conduct wilcox.test
Artist$test_wilcox(formula, data = self$data, ...)
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()
.
A ggplot2 scatter plot.
test_t()
Conduct wilcox.test
Artist$test_t(formula, data = self$data, ...)
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()
.
A ggplot2 scatter plot.
plot_scatter()
Creates a scatter plot.
Artist$plot_scatter( data = self$data, fun = function(x) x, x, y, ..., add = private$is_htest() )
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.
A ggplot2 scatter plot.
plot_box()
Creates a box plot.
Artist$plot_box( data = self$data, fun = function(x) x, x, ..., add = private$is_htest() )
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.
A ggplot2 box plot.
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.
Artist$dumbbbell(data = self$data, x, y, col, ...)
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
.
A ggplot object representing the dumbbell plot.
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.
Artist$bubble(data = self$data, x, y, size, col, ...)
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
.
A ggplot object representing the bubble plot.
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.
Artist$barchart_divergence(data = self$data, group, y, fill, ...)
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
.
A ggplot object representing the divergence bar chart.
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.
Artist$lollipop(data = self$data, x, y, ...)
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
.
A ggplot object representing the lollipop plot.
contour()
Create a contour plot
This method generates a contour plot that includes filled and outlined density contours, with data points overlaid.
Artist$contour(data = self$data, x, y, ...)
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
.
A ggplot object representing the contour plot.
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.
Artist$scatter_ellipses(data = self$data, x, y, col, ...)
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
.
A ggplot object representing the scatter plot with ellipses.
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.
Artist$donut(data = self$data, x, y, fill, ...)
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
.
A ggplot object representing the donut plot.
pie()
Create a pie chart
This method generates a pie chart where sections represent the proportion of categories in the data.
Artist$pie(data = self$data, y, fill, ...)
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
.
A ggplot object representing the pie chart.
clone()
The objects of this class are cloneable with this method.
Artist$clone(deep = FALSE)
deep
Whether to make a deep clone.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.