| Title: | Create Datasets Interactively Using 'shiny' |
|---|---|
| Description: | Set of 'shiny'-based 'RStudio' add-ins for creating datasets by drawing. Users sketch scatter plots, histograms, density curves, boxplots, bivariate normal ellipses, regression curves with error bands, radar profiles, count bar plots and two-way contingency tables (mosaic plots) in an interactive gadget, and each drawing is returned as a data.frame together with a reproducible specification that can regenerate the same data. Methods are described in: Chang et al. (2024) <https://CRAN.R-project.org/package=shiny>; Bostock et al. (2011) <doi:10.1109/TVCG.2011.185>. |
| Authors: | Carlos Rivera [aut, cre] (ORCID: <https://orcid.org/0000-0002-3402-7725>), Heidi Renninger [fnd] (ORCID: <https://orcid.org/0000-0002-2485-9835>), Mike Bostock [cph] (D3.js library, ISC license) |
| Maintainer: | Carlos Rivera <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.5.6 |
| Built: | 2026-11-20 13:06:09 UTC |
| Source: | https://github.com/carlosrivera1212/datacraftr |
Opens the Bivariate gadget. Drag the centre, the major handle and the minor
handle of each group's ellipse to shape a bivariate normal population (up to
ten groups), then press Done to get a random sample of size n per
group.
dcr_bivariate( groups = c("A", "B"), n = 200, xlim = c(0, 10), ylim = c(0, 10), names = c(x = "x", y = "y", group = "group") )dcr_bivariate( groups = c("A", "B"), n = 200, xlim = c(0, 10), ylim = c(0, 10), names = c(x = "x", y = "y", group = "group") )
groups |
Initial group names (1 to 10, unique, non-empty). |
n |
Sample size per group, a whole number from 1 to 1e6 (with |
xlim, ylim
|
Initial axis ranges: two finite numbers, increasing. |
names |
Column names for x, y and group: a character vector of
length 3, named |
A data.frame with x, y and a group factor whose levels are the
groups, carrying its spec (see dcr_spec()); NULL invisibly on Cancel.
if (interactive()) { df <- dcr_bivariate(c("control", "treated"), n = 300) }if (interactive()) { df <- dcr_bivariate(c("control", "treated"), n = 300) }
Opens the Boxplot gadget. Drag the first quartile, median and third
quartile of one box per variable, then press Done to get a random
sample of size n from a two-piece distribution with exactly those
quartiles.
dcr_boxplot( variables = c("V1", "V2", "V3"), n = 100, family = c("normal", "uniform"), ylim = c(0, 10) )dcr_boxplot( variables = c("V1", "V2", "V3"), n = 100, family = c("normal", "uniform"), ylim = c(0, 10) )
variables |
Initial variable names (1 to 10, unique, non-empty). |
n |
Sample size, a whole number from 1 to 1e6. |
family |
Shape of the distribution on each side of the median:
|
ylim |
Initial value range: two finite numbers, increasing. |
A data.frame with one numeric column per variable, carrying its
spec (see dcr_spec()); NULL invisibly on Cancel.
if (interactive()) { df <- dcr_boxplot(c("control", "treated"), n = 200, ylim = c(0, 100)) }if (interactive()) { df <- dcr_boxplot(c("control", "treated"), n = 200, ylim = c(0, 100)) }
Opens the Count gadget. Paint the integer count of every (variable,
category) combination as grouped bars, then press Done to get a data
frame with exactly those counts: one row per observation, with factor
columns variable and category (levels in the drawn order).
dcr_count( variables = c("V1", "V2"), categories = c("C1", "C2", "C3"), ymax = 20 )dcr_count( variables = c("V1", "V2"), categories = c("C1", "C2", "C3"), ymax = 20 )
variables |
Initial variable names (1 to 10, unique, non-empty). |
categories |
Initial category names (1 to 10, unique, non-empty). |
ymax |
Initial top of the count axis, a whole number from 1 to 1e6. |
A data.frame with factor columns variable and category, carrying
its spec (see dcr_spec()); NULL invisibly on Cancel.
if (interactive()) { df <- dcr_count(c("control", "treated"), c("low", "mid", "high")) table(df) }if (interactive()) { df <- dcr_count(c("control", "treated"), c("low", "mid", "high")) table(df) }
Delete a saved DataCraftR dataset
dcr_delete(id)dcr_delete(id)
id |
Id of a saved spec, as shown by |
invisible(TRUE).
if (FALSE) { dcr_delete("boxplot_20261117_153012") }if (FALSE) { dcr_delete("boxplot_20261117_153012") }
Opens the Density gadget. Shape a smooth density curve for each variable
with a soft brush (Pull drags the curve up or down around the point you
press, Paint moves it towards the cursor height), then press Done
to get a random sample of size n from that distribution.
dcr_density(variables = "V1", n = 100, xlim = c(0, 10))dcr_density(variables = "V1", n = 100, xlim = c(0, 10))
variables |
Initial variable names (1 to 10, unique, non-empty). |
n |
Sample size, a whole number from 1 to 1e6. |
xlim |
Initial x range: two finite numbers, increasing. |
A data.frame with one numeric column per variable (variables with
an all-zero curve are dropped with a warning), carrying its spec (see
dcr_spec()); NULL invisibly on Cancel.
if (interactive()) { df <- dcr_density(c("control", "treated"), n = 500, xlim = c(0, 100)) }if (interactive()) { df <- dcr_density(c("control", "treated"), n = 500, xlim = c(0, 100)) }
Opens the Histogram gadget. Paint the bar heights (relative weights, i.e.
the shape of the population) for one histogram per variable, then press
Done to get a random sample of size n from that population.
dcr_histogram(variables = "V1", n = 100, xlim = c(0, 10), nbins = 10)dcr_histogram(variables = "V1", n = 100, xlim = c(0, 10), nbins = 10)
variables |
Initial variable names (1 to 10, unique, non-empty). |
n |
Sample size, a whole number from 1 to 1e6. |
xlim |
Initial x range: two finite numbers, increasing. |
nbins |
Number of bins, a whole number from 1 to 100. |
A data.frame with one numeric column per variable (variables with
all-zero bars are dropped with a warning), carrying its spec (see
dcr_spec()); NULL invisibly on Cancel.
if (interactive()) { df <- dcr_histogram(c("control", "treated"), n = 500, xlim = c(0, 100)) }if (interactive()) { df <- dcr_histogram(c("control", "treated"), n = 500, xlim = c(0, 100)) }
List saved DataCraftR datasets
dcr_list()dcr_list()
A data frame with columns id, tool, created and n (the total
number of rows), newest first. Files in the store that are not readable specs are ignored.
if (FALSE) { dcr_list() }if (FALSE) { dcr_list() }
Tools used from the RStudio Addins menu save their spec in the user data
directory (tools::R_user_dir("DataCraftR", "data")) and insert
df <- dcr_load("<id>") into your script. Literal tools (scatter, count,
mosaic) return exactly what was drawn. Population tools (boxplot, histogram,
density, bivariate, regression, radar) re-sample using the stored seed, so
the same data comes back, unless you give a different seed.
dcr_load(id, n = NULL, seed = NULL)dcr_load(id, n = NULL, seed = NULL)
id |
Id of a saved spec, as shown by |
n |
Number of rows for population tools (per group for bivariate,
regression and radar); defaults to the stored |
seed |
Integer seed for population tools; defaults to the stored seed. |
A data frame (see dcr_sample()).
if (FALSE) { dcr_list() df <- dcr_load("boxplot_20261117_153012") }if (FALSE) { dcr_list() df <- dcr_load("boxplot_20261117_153012") }
Opens the Mosaic gadget. Drag the vertical borders between columns to move
observations between two columns (each keeps its row proportions) and drag
the horizontal cuts inside a column to shift counts between its blocks.
Everything snaps to whole counts and the total stays exactly n. Press
Done to get a data frame with exactly those counts: one row per
observation, with two factor columns (levels in the drawn order).
dcr_mosaic( cols = c("No", "Yes"), rows = c("Healthy", "Sick"), n = 200, names = c(col = "exposure", row = "outcome") )dcr_mosaic( cols = c("No", "Yes"), rows = c("Healthy", "Sick"), n = 200, names = c(col = "exposure", row = "outcome") )
cols, rows
|
Initial category names of the column and row variables (2 to 10 each, unique, non-empty). |
n |
Total number of observations, a whole number from 1 to 1e6. The table starts uniform. |
names |
Names of the two output columns: a character vector of length
2, named |
A data.frame with two factor columns named by names (column
variable first), carrying its spec (see dcr_spec()); NULL invisibly on
Cancel.
if (interactive()) { df <- dcr_mosaic(c("No", "Yes"), c("Healthy", "Sick"), n = 300) table(df) }if (interactive()) { df <- dcr_mosaic(c("No", "Yes"), c("Healthy", "Sick"), n = 300) table(df) }
Opens the Radar gadget. Each group is a profile on a radar chart: drag a
vertex along its spoke to set the mean of a variable and a band handle to
set its standard deviation, then press Done to get a random sample of
size n per group. Values are normal, truncated to each variable's range.
dcr_radar( variables = c("V1", "V2", "V3", "V4", "V5"), groups = c("A", "B"), n = 50, range = c(0, 10), integers = FALSE, group_name = "group" )dcr_radar( variables = c("V1", "V2", "V3", "V4", "V5"), groups = c("A", "B"), n = 50, range = c(0, 10), integers = FALSE, group_name = "group" )
variables |
Variable names (3 to 12, unique, non-empty). |
groups |
Initial group names (1 to 10, unique, non-empty). |
n |
Sample size per group, a whole number from 1 to 1e6 (with |
range |
Initial range of every variable: two finite numbers, increasing, or a list with one such pair per variable. |
integers |
If |
group_name |
Name of the group column; it must differ from the variable names. |
A data.frame with a group factor (levels are the groups) and one
numeric column per variable, carrying its spec (see dcr_spec());
NULL invisibly on Cancel.
if (interactive()) { df <- dcr_radar(c("speed", "power", "agility"), groups = c("A", "B")) }if (interactive()) { df <- dcr_radar(c("speed", "power", "agility"), groups = c("A", "B")) }
Opens the Regression gadget. Shape the mean curve f(x) and the error
spread around it for each group (Pull and Paint brushes, or type an
equation), then press Done to get a random sample of size n per group.
dcr_regression( f = "x", groups = "A", n = 200, xlim = c(0, 10), sd = 1, names = c(x = "x", y = "y", group = "group"), shared_x = TRUE )dcr_regression( f = "x", groups = "A", n = 200, xlim = c(0, 10), sd = 1, names = c(x = "x", y = "y", group = "group"), shared_x = TRUE )
f |
The initial curve: one equation (a string in |
groups |
Initial group names (1 to 10, unique, non-empty). |
n |
Sample size per group, a whole number from 1 to 1e6 (with |
xlim |
Initial x range: two finite numbers, increasing. |
sd |
Initial error standard deviation: one value or one per group, each at least 0. |
names |
Column names for x, y and group: a character vector of
length 3, named |
shared_x |
If |
An equation given as a string or function is evaluated in R in your session, like any other R code you run.
A data.frame with x, y and a group factor whose levels are the
groups, carrying its spec (see dcr_spec()); NULL invisibly on Cancel.
if (interactive()) { df <- dcr_regression("2 + 0.5 * x", groups = c("control", "treated")) }if (interactive()) { df <- dcr_regression("2 + 0.5 * x", groups = c("control", "treated")) }
Turns a spec (what was drawn) into a data frame. Population tools draw n
rows using seed; literal tools return exactly what was drawn and ignore
n and seed. The session's random number state (.Random.seed) is
left as it was.
dcr_sample(spec, n = NULL, seed = NULL)dcr_sample(spec, n = NULL, seed = NULL)
spec |
A |
n |
Number of rows for population tools (per group for bivariate,
regression and radar); defaults to |
seed |
Optional integer seed; defaults to |
A data frame with attribute "dcr_spec" holding the spec used (with
n and seed set to the values used).
if (FALSE) { df <- dcr_sample(dcr_spec(my_df), n = 200, seed = 1) }if (FALSE) { df <- dcr_sample(dcr_spec(my_df), n = 200, seed = 1) }
Opens the Scatter gadget. Spray, place or erase points for up to ten groups, then press Done to get exactly the drawn points.
dcr_scatter( xlim = c(0, 10), ylim = c(0, 10), groups = c("A", "B", "C"), names = c(x = "x", y = "y", group = "group") )dcr_scatter( xlim = c(0, 10), ylim = c(0, 10), groups = c("A", "B", "C"), names = c(x = "x", y = "y", group = "group") )
xlim, ylim
|
Initial axis ranges: two finite numbers, increasing. |
groups |
Initial group names (1 to 10, unique, non-empty). |
names |
Column names for x, y and group: a character vector of
length 3, named |
A data.frame with the drawn points (x, y and a group factor whose
levels are the groups), carrying its spec (see dcr_spec()); NULL
invisibly on Cancel.
if (interactive()) { df <- dcr_scatter(xlim = c(-5, 5), groups = c("control", "treated")) }if (interactive()) { df <- dcr_scatter(xlim = c(-5, 5), groups = c("control", "treated")) }
Recover the spec behind a DataCraftR data frame
dcr_spec(df)dcr_spec(df)
df |
A data frame returned by a DataCraftR tool. |
A dcr_spec object.