How do you create an empty plot in R? 2

How do you create an empty plot in R?

To create an empty plot in R, use the “plot()” function and specify the x and y axis ranges using the “xlim” and “ylim” parameters. Additionally, set the “type” parameter to “n” to create an empty plot with no data points. This will create a blank canvas for adding data and customizing the plot. Other parameters, such as “main” for the plot title and “xlab” and “ylab” for axes labels, can also be specified to further customize the empty plot.

Create an Empty Plot in R (3 Examples)


There are three common ways to create an empty plot in R:

Method 1: Create Completely Empty Plot

plot.new()

Method 2: Create Empty Plot with Axes

plot(NULL, xlab="", ylab="", xaxt="n", yaxt="n",
     xlim=c(0, 10), ylim=c(0, 10))

Method 3: Create Empty Plot with Axes & Labels

plot(NULL, ylab="y label", xlab="x label", main="title",
     xlim=c(0, 10), ylim=c(0, 10))

The following example shows how to use each method in practice.

Example 1: Create Completely Empty Plot

We can use the following code to create a completely empty plot in R:

plot.new()

Here’s what the result looks like in the plotting window in RStudio:

Example 2: Create Empty Plot with Axes

We can use the following code to create an empty plot with axes in R:

plot(NULL, xlab="", ylab="", xaxt="n", yaxt="n",
     xlim=c(0, 10), ylim=c(0, 10))

Here’s what the result looks like in the plotting window in RStudio:

Note that the xaxt and yaxt arguments suppress the tick marks on the x-axis and y-axis, respectively. 

Example 3: Create Empty Plot with Axes & Labels

We can use the following code to create an empty plot with axes and labels in R:

plot(NULL, ylab="y label", xlab="x label", main="title",
     xlim=c(0, 10), ylim=c(0, 10))

Here’s what the result looks like in the plotting window in RStudio:

Additional Resources

The following tutorials explain how to perform other common tasks in R:

Cite this article

stats writer (2024). How do you create an empty plot in R?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-do-you-create-an-empty-plot-in-r/

stats writer. "How do you create an empty plot in R?." PSYCHOLOGICAL SCALES, 28 Jun. 2024, https://scales.arabpsychology.com/stats/how-do-you-create-an-empty-plot-in-r/.

stats writer. "How do you create an empty plot in R?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-do-you-create-an-empty-plot-in-r/.

stats writer (2024) 'How do you create an empty plot in R?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-do-you-create-an-empty-plot-in-r/.

[1] stats writer, "How do you create an empty plot in R?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How do you create an empty plot in R?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top