Skip to contents
library(youdrawitR)
set.seed(123)
data <- linearDataGen(y_int = 0,
                      slope = 1,
                      sigma = 1.5,
                      N = 30,
                      conf_int = F)

The YouDrawIt package allows for creating interactive plots where users can make their own predictions and see how they match up to the actual data. The package is equipped with a multitude of customization options and this guide will help you to understand how you can customize the plots created by the drawr() function and make the most of the button features.

Customizing The Plot

Axis Range & Labels

There are two ways to customize the range of values displayed on the x and y axis. Be aware, even if the specified range is smaller than the range of the point data, the line is still fitted for all points in the dataset.

The first way is to specify the x_range and y_range that you want for the data. If left as NULL (the default), the function will automatically use the range of the max of the line and point data x and y values.

See Example
drawr(data = data, x_range = c(0, 25), y_range = c(-2, 20))
#> Warning in drawr(data = data, x_range = c(0, 25), y_range = c(-2, 20)): The
#> provided y_range does not cover data, the line will still be fitted from entire
#> dataset.

The second way is to specify a x_axis_buffer or y_axis_buffer. This will add a buffer to the axis, as a percent of total range. Thus, your input must be greater than or equal to 0.

See Example
drawr(data = data, x_axis_buffer = 0.1, y_axis_buffer = 0.1)

To add axis labels use the x_lab and y_lab parameters. To add titles use the title and subtitle parameters. Here is an example of how to use these parameters.

See Example
drawr(data = data, title = "Sales Over Time", x_lab = "Time", y_lab = "Sales")

Color Customization

There are numerous visualization parameters too change the appearance of the plot and the most notable are the changes you can make to the colors. These options include:

  1. drawn_line_color: This parameter changes the color of the lines that the user draws on the plot.

  2. true_line_color: This parameter changes the color of the actual line and optionally confidence interval region in the plot, which is revealed when the user clicks the ‘Show True Line’ button.

  3. draw_region_color: This parameter changes the color of the drawing region, which is the area that shows the user’s progress as they draw the line.

The default drawn_line_color and true_line_color are “steelblue” let’s generate a confidence interval to truly showcase how the color changes. Remember, you must generate the confidence interval in the data generator first to display it in the drawr() function. In this example we will use a “red” drawing color and a “purple” true_line/conf_int color. Remember to see the true line, you must complete complete the graph (shown by the yellow progress region). Try for yourself in the example below!

See Example
# Generate new data with confidence interval
conf_data <- linearDataGen(y_int = 0,
                      slope = 1,
                      sigma = 2.5,
                      N = 20,
                      conf_int = T)

# Create plot with new color paramaters and display confidence interval region
drawr(data = conf_data,
      drawn_line_color = "red",
      true_line_color = "purple",
      conf_int = T)

Changing the draw_region_color is also an option. This can be changed to any color and can even be removed by choosing “white” or NULL, however this is not recommended as the progress region has been made to help the user when completing the line. If removing the draw region, it is recommended to use show_tooltip = TRUE so the user has a way to know if they have skipped over a portion of the line. This tooltip will display progress when hovering over the area that has not yet been drawn over with the connected line.

Example with different draw_region_color
drawr(data = data,
      draw_region_color = "green")
Example with draw region removed
drawr(data = data,
      draw_region_color = NULL,
      show_tooltip = TRUE)

For more information on other plot customization options, make sure to go to the drawr() function documentation.

Understanding and Using the Buttons

The drawr() function provides three main interactive buttons: Reset, Download Data, and New Line/Stop Drawing. Here’s how you can utilize them:

  • Reset Button: Clicking this button will erase all user-drawn lines, and allows you to start over from scratch.

  • Download Data Button: This button downloads your data as a JSON text file. The downloaded data includes both the original line and any new lines drawn by the user. It will split the data in to two section in the text file, making it easy to find. Just look for “original line:” for the original line and “new lines:” for any added lines.

  • New Line/Stop Drawing Button: This button toggles between adding a new line and extending the original line. Clicking it once initiates the drawing of a new line, and the button turns red. A second click, when the button reads “Stop Drawing”, concludes the new line’s drawing and reverts back to modifying the original line. Keep in mind, once a new line is concluded, it can no longer be edited.

  • Line Color Picker: Upon clicking the “New Line” button, a color palette appears under the buttons. This palette lets you pick the color for your new line, enhancing visual distinction between different lines. Simply click on the color block of your choice before starting to draw or while drawing. The color palette will disappear once a color is selected or when you click “Stop Drawing” or “Reset”. If no color is chosen the default will be “steelblue”.

Additionally, you can hide these buttons to reduce interface clutter or when you don’t need their functionality. This can be achieved by setting the hide_buttons = TRUE parameter in the drawr() function.

Here is an example of how to hide the buttons in your output:

See Example
drawr(data = data,
      hide_buttons = TRUE)

Now that you are familiar with the functionality of the buttons in the drawr() function, why not try them out for yourself in the example below? In the following plot, use the “New Line/Stop Drawing” button to start and stop drawing new lines, the “Download Data” button to save your work, and the “Reset” button to clear all lines and restart if you mess up.

See Example
drawr(data = data,
      hide_buttons = FALSE)

Examples of Using the New Line Button

The New Line button in drawr() opens up a range of possibilities for interactive data analysis and visualization. Here are a few examples of how you can leverage this feature:

Confidence/Prediction Intervals: By drawing additional lines above and below the original regression line, you can create a visual representation of confidence or prediction intervals. This can give a sense of the variability in your data and the precision of your predictions. Additionally, you can check your own drawn confidence intervals with generated confidence intervals from the linearDataGen() or customDataGen() functions.

Model Deviation: Sketch lines or shapes to indicate where your data diverges from the model predictions. This can help in visualizing the residuals or variance around your regression line. It can also help visualize if your model’s errors are normally distributed (drawing a bell shape) or if they have some sort of skewness or patterns that might need further investigation.

Outlier Identification: Use the New Line button to draw shapes around potential outliers. This makes them easy to identify and discuss.

Areas of Interest: Highlight specific regions on the graph that you want to focus on or further investigate.

Analyzing Potential Outcomes: Use the New Line button to visualize the implications of changes to your data. For instance, if you have certain expectations about how your data might evolve in the future, you could draw these as new lines on your graph. This could include potential increases or decreases in trends, the emergence of new patterns, or changes to the variability of your data. By visualizing these different potential outcomes, you can more effectively prepare for these possibilities and understand how they might impact your model’s predictions.

Remember, these are just a few examples and there might be many other creative ways to use the New Line button, depending on your specific use case and data analysis/educative needs.