International College of Digital Innovation, CMU
June 24, 2026
viewof modType = Inputs.radio(
[
"1) Modifying Axes",
"2) Modifying Points (size/color)",
"3) Change Point Shape (pch)",
"4) Titles & Subtitles",
"5) Add Grid",
"6) Add Lines (trend/reference)",
"7) Text Annotations",
"8) Legends",
"9) Customize Plot Margins",
"10) Custom Axes (axes=FALSE; axis())",
"11) Background Color: Plot Region",
"12) Background + Grid (panel look)",
"13.1) Multiple Plots Row (mfrow)",
"13.2) Multiple Plots Column (mfcol)",
"13.3) Custom Layout (layout())"
],
{ label: "Modify Base Plot", value: "1) Modifying Axes", inline: false }
)Modifying a plot in the base R package can be done using various parameters within the plot() function, as well as adding additional elements using other base plotting functions like lines(), points(), abline(), text(), legend(), etc.
Here’s a guide on how to modify different aspects of a plot in base R:
Custom Axis Labels: Use xlab and ylab to modify the axis labels.
Custom Axis Limits: Use xlim and ylim to set the limits of the x and y axes.
Custom Axis Ticks: Use axis() to customize the ticks and labels.
Point Shape: Use pch to change the shape of the points.
Point Size: Use cex to change the size of the points.
Point Color: Use col to change the color of the points.
Note: The pch = 0 is useless, then we will not consider on this value.
The pch = 15 to 20 are useful for the argument col.
Main Title: Use main to add a main title.
Subtitle: Use sub to add a subtitle.
Adding Grid Lines: Use grid() to add grid lines to the plot.
argument
nx, ny number of cells of the grid in x and y direction (try: nx = NA, ny = NULL or nx = NULL, ny = NA)
col color of grid lines.
lty line type of the grid lines. (1-6)
lwd line width of the grid lines
Adding a Line through Points: Use lines() to add a line connecting points.
Adding a Regression Line: Use abline() to add a regression line.
Adding Text: Use text() to add text annotations to specific points.
Positioning Text: Use pos, adj, and offset to control the position of the text.
legend() to add a legend to the plot.Custom Margins: Use par(mar = c(bottom, left, top, right)) to adjust the margins.
Suppress Default Axes: Use axes = FALSE in plot() and add custom axes with axis().
We can modify the background color of a base R plot using the bg parameter within the par() function.
Explanation:
par(bg = "lightblue"): This sets the background color of the plot to light blue.
par(bg = "white"): This resets the background color to white for subsequent plots, ensuring that only the current plot is affected.
You can replace “lightblue” with any valid color name or hexadecimal color code (e.g., “#FFD700” for lightblue) to customize the background color as desired.
bg = NULL.In a base R plot, you can use the rect() function after creating the plot.
Explanation:
plot(..., type = "n"): Creates an empty plot with the axes and labels but without plotting the data points.
rect(...): Draws a rectangle that covers the entire plot area using the coordinates obtained from par("usr"). The col parameter sets the background color, and border = NA removes the border around the rectangle.
points(): Adds the data points on top of the custom background.
The mfrow parameter arranges plots in a row-wise manner.
The mfcol parameter arranges plots in a column-wise manner.
For more complex layouts, you can use the layout() function, which allows for custom arrangements, including varying plot sizes.
Complete the script to configure a bivariate scatter plot, assigning a specific aesthetic color property and custom plotting symbol layers.
viewof var_ex1_changing_colors_symbols_1 = html`<input type="text" class="ojs-hidden-ex1_changing_colors_symbols" data-ojs-proxy="ex1_changing_colors_symbols::var_ex1_changing_colors_symbols_1" value="">`
viewof var_ex1_changing_colors_symbols_2 = html`<input type="text" class="ojs-hidden-ex1_changing_colors_symbols" data-ojs-proxy="ex1_changing_colors_symbols::var_ex1_changing_colors_symbols_2" value="">`
viewof var_ex1_changing_colors_symbols_run = html`<input type="number" class="ojs-hidden-ex1_changing_colors_symbols" data-ojs-run="ex1_changing_colors_symbols" value="0">`Complete the script to generate a bivariate scatter plot and apply distinct text strings to structural title and axis label parameters.
viewof var_ex2_adding_titles_labels_1 = html`<input type="text" class="ojs-hidden-ex2_adding_titles_labels" data-ojs-proxy="ex2_adding_titles_labels::var_ex2_adding_titles_labels_1" value="">`
viewof var_ex2_adding_titles_labels_2 = html`<input type="text" class="ojs-hidden-ex2_adding_titles_labels" data-ojs-proxy="ex2_adding_titles_labels::var_ex2_adding_titles_labels_2" value="">`
viewof var_ex2_adding_titles_labels_3 = html`<input type="text" class="ojs-hidden-ex2_adding_titles_labels" data-ojs-proxy="ex2_adding_titles_labels::var_ex2_adding_titles_labels_3" value="">`
viewof var_ex2_adding_titles_labels_run = html`<input type="number" class="ojs-hidden-ex2_adding_titles_labels" data-ojs-run="ex2_adding_titles_labels" value="0">`Complete the multi-stage rendering script to initialize an empty canvas, paint the bounded graphical viewport region, and overlay coordinate observations.
viewof var_ex3_modifying_background_color_1 = html`<input type="text" class="ojs-hidden-ex3_modifying_background_color" data-ojs-proxy="ex3_modifying_background_color::var_ex3_modifying_background_color_1" value="">`
viewof var_ex3_modifying_background_color_2 = html`<input type="text" class="ojs-hidden-ex3_modifying_background_color" data-ojs-proxy="ex3_modifying_background_color::var_ex3_modifying_background_color_2" value="">`
viewof var_ex3_modifying_background_color_3 = html`<input type="text" class="ojs-hidden-ex3_modifying_background_color" data-ojs-proxy="ex3_modifying_background_color::var_ex3_modifying_background_color_3" value="">`
viewof var_ex3_modifying_background_color_run = html`<input type="number" class="ojs-hidden-ex3_modifying_background_color" data-ojs-run="ex3_modifying_background_color" value="0">`Complete the script to construct a bivariate coordinate space and layer structural alignment grids onto the active viewport canvas.
viewof var_ex4_adding_grid_lines_1 = html`<input type="text" class="ojs-hidden-ex4_adding_grid_lines" data-ojs-proxy="ex4_adding_grid_lines::var_ex4_adding_grid_lines_1" value="">`
viewof var_ex4_adding_grid_lines_2 = html`<input type="text" class="ojs-hidden-ex4_adding_grid_lines" data-ojs-proxy="ex4_adding_grid_lines::var_ex4_adding_grid_lines_2" value="">`
viewof var_ex4_adding_grid_lines_run = html`<input type="number" class="ojs-hidden-ex4_adding_grid_lines" data-ojs-run="ex4_adding_grid_lines" value="0">`Complete the script to suppress the default horizontal and vertical coordinate axes, instantiate tailored scaling boundaries, and layer the observation nodes.
viewof var_ex5_customizing_axes_1 = html`<input type="text" class="ojs-hidden-ex5_customizing_axes" data-ojs-proxy="ex5_customizing_axes::var_ex5_customizing_axes_1" value="">`
viewof var_ex5_customizing_axes_2 = html`<input type="text" class="ojs-hidden-ex5_customizing_axes" data-ojs-proxy="ex5_customizing_axes::var_ex5_customizing_axes_2" value="">`
viewof var_ex5_customizing_axes_3 = html`<input type="text" class="ojs-hidden-ex5_customizing_axes" data-ojs-proxy="ex5_customizing_axes::var_ex5_customizing_axes_3" value="">`
viewof var_ex5_customizing_axes_4 = html`<input type="text" class="ojs-hidden-ex5_customizing_axes" data-ojs-proxy="ex5_customizing_axes::var_ex5_customizing_axes_4" value="">`
viewof var_ex5_customizing_axes_run = html`<input type="number" class="ojs-hidden-ex5_customizing_axes" data-ojs-run="ex5_customizing_axes" value="0">`Complete the script to split the structural graphical window into a multi-panel layout matrix and execute sequential plotting commands.
viewof var_ex6_multiple_plots_grid_1 = html`<input type="text" class="ojs-hidden-ex6_multiple_plots_grid" data-ojs-proxy="ex6_multiple_plots_grid::var_ex6_multiple_plots_grid_1" value="">`
viewof var_ex6_multiple_plots_grid_run = html`<input type="number" class="ojs-hidden-ex6_multiple_plots_grid" data-ojs-run="ex6_multiple_plots_grid" value="0">`Complete the script to split the graphical viewport using an asymmetric matrix schema and arrange subplots with custom height and width constraints.
viewof var_ex7_custom_plot_layout_1 = html`<input type="text" class="ojs-hidden-ex7_custom_plot_layout" data-ojs-proxy="ex7_custom_plot_layout::var_ex7_custom_plot_layout_1" value="">`
viewof var_ex7_custom_plot_layout_2 = html`<input type="text" class="ojs-hidden-ex7_custom_plot_layout" data-ojs-proxy="ex7_custom_plot_layout::var_ex7_custom_plot_layout_2" value="">`
viewof var_ex7_custom_plot_layout_run = html`<input type="number" class="ojs-hidden-ex7_custom_plot_layout" data-ojs-run="ex7_custom_plot_layout" value="0">`Complete the script to evaluate transmission groupings, map dynamic vectors to aesthetic point colors, and deploy an explanatory legend map.
viewof var_ex8_adding_legend_1 = html`<input type="text" class="ojs-hidden-ex8_adding_legend" data-ojs-proxy="ex8_adding_legend::var_ex8_adding_legend_1" value="">`
viewof var_ex8_adding_legend_2 = html`<input type="text" class="ojs-hidden-ex8_adding_legend" data-ojs-proxy="ex8_adding_legend::var_ex8_adding_legend_2" value="">`
viewof var_ex8_adding_legend_run = html`<input type="number" class="ojs-hidden-ex8_adding_legend" data-ojs-run="ex8_adding_legend" value="0">`Complete the script to pinpoint the structural maximum outlier and overlay an explicit textual callout annotation onto the target coordinate.
viewof var_ex9_adding_text_annotations_1 = html`<input type="text" class="ojs-hidden-ex9_adding_text_annotations" data-ojs-proxy="ex9_adding_text_annotations::var_ex9_adding_text_annotations_1" value="">`
viewof var_ex9_adding_text_annotations_2 = html`<input type="text" class="ojs-hidden-ex9_adding_text_annotations" data-ojs-proxy="ex9_adding_text_annotations::var_ex9_adding_text_annotations_2" value="">`
viewof var_ex9_adding_text_annotations_run = html`<input type="number" class="ojs-hidden-ex9_adding_text_annotations" data-ojs-run="ex9_adding_text_annotations" value="0">`