Table of Contents
Points can be added to an existing plot in R by using the plot() function and specifying the “points” argument. This argument takes in the coordinates of the points to be added and can also include other parameters such as color, size, and shape of the points. Alternatively, the points can also be added using the points() function, which allows for more customization options such as adding labels and changing the appearance of individual points. Both of these methods can be used to enhance the visual representation of data in an existing plot in R.
Add Points to an Existing Plot in R
You can use the points() function to add points to an existing plot in R.
This function uses the following basic syntax:
points(df2$x, df2$y, col='red')
This particular syntax adds red points to an existing scatter plot in R using the variables called x and y from a data frame called df2.
The following example shows how to use this syntax in practice.
Example: Add Points to an Existing Plot in R
Suppose we use the plot() function to create the following scatter plot in R:
#create data frame df1 <- data.frame(x=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), y=c(4, 5, 5, 4, 6, 8, 12, 15, 19, 22)) #create scatterplot plot(df1$x, df1$y, col='blue', pch=16)

Note: The col argument specifies the color of the points in the plot and the pch argument specifies the symbol to use. A value of 16 represents a filled-in circle.
Now suppose that we would like to add points from another data frame to the plot.
We can use the points() function to do so:
#create second data frame df2 <- data.frame(x=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), y=c(14, 12, 9, 9, 8, 5, 4, 5, 3, 2)) #add points from df2 to the existing scatter plot points(df2$x, df2$y, col='red', pch=16)

Notice that the points from the second data frame have been added to the existing plot and are represented by a red color.
If we’d like, we can also use the legend() function to add a legend to the plot so that we can distinguish which points came from which data frame:
#add legend to plot legend(x=1, y=22, legend=c('df1', 'df2'), fill=c('blue', 'red'))

Note: You can use the points() function as many times as you’d like to add points from as many data frames as you’d like to an existing plot.
Cite this article
stats writer (2024). How can points be added to an existing plot in R?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-points-be-added-to-an-existing-plot-in-r/
stats writer. "How can points be added to an existing plot in R?." PSYCHOLOGICAL SCALES, 26 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-points-be-added-to-an-existing-plot-in-r/.
stats writer. "How can points be added to an existing plot in R?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-points-be-added-to-an-existing-plot-in-r/.
stats writer (2024) 'How can points be added to an existing plot in R?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-points-be-added-to-an-existing-plot-in-r/.
[1] stats writer, "How can points be added to an existing plot in R?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can points be added to an existing plot in R?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
