Skip to contents

drawr() draws an interactive you-draw-it plot for interactive testing of graphics. Data can be simulated using linearDataGen() or inputted using a data frame from customDataGen().

Usage

drawr(
  data,
  save_html_file_path = NULL,
  hide_buttons = FALSE,
  conf_int = FALSE,
  linear = "true",
  log_base = NULL,
  draw_start = NULL,
  points_end = NULL,
  x_by = 0,
  free_draw = TRUE,
  points = "full",
  aspect_ratio = 1,
  title = "",
  x_range = NULL,
  y_range = NULL,
  x_lab = "",
  y_lab = "",
  subtitle = "",
  drawn_line_color = "steelblue",
  true_line_color = "steelblue",
  draw_region_color = "rgba(255,255,0,.8)",
  x_axis_buffer = 0,
  y_axis_buffer = 0.05,
  show_finished = TRUE,
  show_tooltip = FALSE
)

Arguments

data

The data containing line data (with equation info) and point data.

save_html_file_path

File path to save d3 output as an html. If null will not save. Can just provide filename and will save to current working directory. (default: NULL)

hide_buttons

Logical value indicating whether to show or hide buttons. TRUE = hide, FALSE = show (default: FALSE)

conf_int

Whether to generate a 95% confidence interval for the fitted line. Must select conf_int = TRUE in linearDataGen() or customDataGen() functions to generate interval. (default: FALSE)

linear

Choice of a linear or log y-scale, "true" = linear, else = log. If using log scale choose log_y = TRUE in customDataGen() function when generating data. (default: "true").

log_base

The base of the log scale, only affects graph if not linear is not "true". If NULL will use natural logarithm. Log_base should match log_base choice in customDataGen() function (default = NULL)

draw_start

The starting point for drawing. Must be larger than minimum x value and smaller than maximum x value. If null is provided will use minimum x plus smallest possible positive number such that x min != sum. Only provide if free_draw != TRUE. (default: NULL).

points_end

The ending x-value for the points. Will only affect the graph if points are "partial" (default: NULL).

x_by

The offset applied to rectangle in relation to current progress. (default: 0)

free_draw

Whether to allow freehand drawing for entire graph. If false, begin drawing at draw_start. (default: T).

points

The type of points to be displayed. Choices: "full" or "partial". Full will always display all points, while for partial the user can choose not to include points. (default: "full").

aspect_ratio

The aspect ratio of the plot (default: 1).

title

The title of the plot. (default: "")

x_range

The range of x values. If null is provided will use range of line data x values. WARNING: even if x_range is smaller than x range of point data, the line is still fitted for all points in dataset. (default: NULL)

y_range

The range of y values. If null is provided will use range of line data y values. WARNING: even if y_range is smaller than y range of point data, the line is still fitted for all points in dataset. (default: NULL)

x_lab

The x-axis label. (default: "")

y_lab

The y-axis label. (default: "")

subtitle

The subtitle of the plot. (default: "")

drawn_line_color

The color of the drawn lines. (default: "steelblue")

true_line_color

The color of the true drawn lines and confidence interval region. (default: "steelblue")

draw_region_color

The color of the drawing region that displays progress. If NULL, region will be transparent. (default: "rgba(255,255,0,.8)" (yellow))

x_axis_buffer

The buffer for the x-axis added to the x range, calculated as a percent of x range. Only used if x_range is NULL, and must be greater than or equal to 0. (default: 0)

y_axis_buffer

The buffer for the y-axis added to the y range, calculated as a percent of y range. Only used if y_range is NULL, and must be greater than or equal to 0. (default: 0.05)

show_finished

Whether to show the finished plot (default: TRUE).

show_tooltip

Whether to display tooltips or not. (default: FALSE)

Value

The rendered interactive you-draw-it plot. The plot is displayed automatically when function is called if not assigned to a variable for further use.

Examples

# Example 1: Simulating linear data and plotting
data <- linearDataGen(y_int = -4,
                      slope  = 0.8,
                      sigma  = 2.8,
                      x_min  = 0,
                      x_max  = 20,
                      N      = 40)
print(drawr(data))

# Example 2: Using custom data frame and custom options
df <- data.frame(Time = c(0, 1, 2, 3, 4, 5, 9, NA, 12, 6, 7),
                 Cost = c(NA, 2, 4, 6, 8, 10, 18, 12, 10, 14, 14))
data <- customDataGen(df, "Time", "Cost")
print(drawr(data           = data,
            aspect_ratio   = 0.85,
            title          = "Title",
            x_range        = c(0, 15),
            subtitle       = "Subtitle",
            x_lab          = "x-axis",
            y_lab          = "y-axis",
            x_axis_buffer  = 0,
            y_axis_buffer  = 1,
            show_tooltip   = TRUE))
            
# Example 3: Using a non-linear scale
df <- data.frame(Time = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
df$Cost <- exp(df$Time)
data <- customDataGen(df = df, log_y = TRUE, log_base = 2)
print(drawr(data, linear = "no", log_base = 2))

# Example 4: Start drawing in the middle and include tooltips
df <- data.frame(
  Time = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
  Cost = c(1, 4, 9, 16, 18, 16, 9, 4, 2, 1)
)

data <- df |>  customDataGen()

print(drawr(data, free_draw = FALSE, draw_start = 5))