International College of Digital Innovation, CMU
September 10, 2026
viewof scatterType = Inputs.radio(
[
"Basic Scatter Plot",
"Scatter Plot with Colors & Shapes",
"Scatter Plot with Regression Line",
"Scatter Plot with Groups",
"Scatter Plot with Text Labels",
"Scatter Plot with Size Mapping",
"Scatter Plot Matrix"
],
{ label: "Scatter Plot Types", value: "Basic Scatter Plot", inline: true }
)A scatter plot is a type of data visualization that is used to display the relationship between two continuous variables.
It is often employed in statistics and data analysis to identify patterns, trends, and correlations between the variables.
In a scatter plot, each data point is represented by a dot, and the position of the dot on the graph corresponds to the values of the two variables.
The horizontal axis (x-axis) typically represents one variable, while the vertical axis (y-axis) represents the other variable.
Each point on the graph represents a pair of values from the two variables.
By examining the distribution of points, you can gain insights into the nature of the relationship between the variables.
Scatter plots are particularly useful for identifying trends, outliers, clusters, or any patterns that may exist in the data.
To create a scatter plot in R using the plot() function, we need to provide the vectors or data frames representing the variables you want to plot on the x-axis and y-axis.
example:
In this example
x and y are vectors representing the data for the x-axis and y-axis, respectively.
main, xlab, and ylab are optional parameters specifying the main title, x-axis label, and y-axis label, respectively.
pch sets the type of plotting symbol (in this case, a solid dot).
col sets the color of the dots.
You can customize these parameters based on your specific data and preferences. If you have a data frame, you can use column names to access variables. For example:
This example assumes a simple scatter plot, but you can use additional parameters and functions to add more features, such as regression lines, labels, and more, depending on your analysis requirements.
In R, the pch (plot character) argument is used in the base plot function to specify the type of plotting symbol or point character to be used in the scatter plot.
The pch parameter allows you to customize the appearance of the points on the plot.
Some common values for the pch argument:
pch = 1: Hollow circlepch = 2: Filled circlepch = 3: Crosspch = 4: Xpch = 5: Diamondpch = 6: Squarepch = 7: Triangle point uppch = 8: Triangle point downpch = 9: Solid dotThe pch argument is used to change the plotting symbols for different groups of points.
The legend() function is used to add a legend explaining the meaning of each pch value.
You can experiment with different pch values to customize the appearance of points in your scatter plot based on your preferences.
The important argument for scatter plot
bg = Fill color inside the symbol.
col = Border color the symbol
Can you see something ?
If speed is greater than 20, assign the color red; otherwise, assign blue.
If speed is less than 10 and distance is less than 40, assign the color red; otherwise, assign blue.
scatter plot between lifeExp vs gdpPercap
The scatter plot between lifeExp vs gdpPercap select the data only year 2007
The scatter plot between lifeExp vs gdpPercap select the data only year 2007
add linear regression blue line
pch is red circle.
select “Accent”
Basic way
Complete the script to map two numeric vectors from the mtcars dataset onto a bivariate scatter plot and assign a descriptive main title.
viewof var_ex1_basic_scatter_plot_1 = html`<input type="text" class="ojs-hidden-ex1_basic_scatter_plot" data-ojs-proxy="ex1_basic_scatter_plot::var_ex1_basic_scatter_plot_1" value="">`
viewof var_ex1_basic_scatter_plot_2 = html`<input type="text" class="ojs-hidden-ex1_basic_scatter_plot" data-ojs-proxy="ex1_basic_scatter_plot::var_ex1_basic_scatter_plot_2" value="">`
viewof var_ex1_basic_scatter_plot_run = html`<input type="number" class="ojs-hidden-ex1_basic_scatter_plot" data-ojs-run="ex1_basic_scatter_plot" value="0">`Complete the script to render a bivariate scatter plot, map point colors dynamically based on grouping levels, and expand the physical symbol scales.
viewof var_ex2_customizing_points_1 = html`<input type="text" class="ojs-hidden-ex2_customizing_points" data-ojs-proxy="ex2_customizing_points::var_ex2_customizing_points_1" value="">`
viewof var_ex2_customizing_points_2 = html`<input type="text" class="ojs-hidden-ex2_customizing_points" data-ojs-proxy="ex2_customizing_points::var_ex2_customizing_points_2" value="">`
viewof var_ex2_customizing_points_run = html`<input type="number" class="ojs-hidden-ex2_customizing_points" data-ojs-run="ex2_customizing_points" value="0">`Complete the script to map the bivariate coordinates, fit a linear regression model, and superimpose the estimated trendline onto the active canvas.
viewof var_ex3_adding_regression_line_1 = html`<input type="text" class="ojs-hidden-ex3_adding_regression_line" data-ojs-proxy="ex3_adding_regression_line::var_ex3_adding_regression_line_1" value="">`
viewof var_ex3_adding_regression_line_run = html`<input type="number" class="ojs-hidden-ex3_adding_regression_line" data-ojs-run="ex3_adding_regression_line" value="0">`Complete the script to map the bivariate coordinates and overlay textual identifier labels at specific discrete observation points.
viewof var_ex4_adding_text_annotations_1 = html`<input type="text" class="ojs-hidden-ex4_adding_text_annotations" data-ojs-proxy="ex4_adding_text_annotations::var_ex4_adding_text_annotations_1" value="">`
viewof var_ex4_adding_text_annotations_2 = html`<input type="text" class="ojs-hidden-ex4_adding_text_annotations" data-ojs-proxy="ex4_adding_text_annotations::var_ex4_adding_text_annotations_2" value="">`
viewof var_ex4_adding_text_annotations_run = html`<input type="number" class="ojs-hidden-ex4_adding_text_annotations" data-ojs-run="ex4_adding_text_annotations" value="0">`Complete the script to render a multivariate scatter plot, map point aesthetics dynamically, and position an explanatory classification legend.
viewof var_ex5_scatter_plot_multiple_groups_1 = html`<input type="text" class="ojs-hidden-ex5_scatter_plot_multiple_groups" data-ojs-proxy="ex5_scatter_plot_multiple_groups::var_ex5_scatter_plot_multiple_groups_1" value="">`
viewof var_ex5_scatter_plot_multiple_groups_2 = html`<input type="text" class="ojs-hidden-ex5_scatter_plot_multiple_groups" data-ojs-proxy="ex5_scatter_plot_multiple_groups::var_ex5_scatter_plot_multiple_groups_2" value="">`
viewof var_ex5_scatter_plot_multiple_groups_3 = html`<input type="text" class="ojs-hidden-ex5_scatter_plot_multiple_groups" data-ojs-proxy="ex5_scatter_plot_multiple_groups::var_ex5_scatter_plot_multiple_groups_3" value="">`
viewof var_ex5_scatter_plot_multiple_groups_run = html`<input type="number" class="ojs-hidden-ex5_scatter_plot_multiple_groups" data-ojs-run="ex5_scatter_plot_multiple_groups" value="0">`