How to create an empty plot in R [chart with no data points]

When doing data science there are occasions when you are going to need to use an empty graph. An empty plot is a plot that does not have any data points. It can contain every other part of a plot including labels but simply lacks the data that would normally fill it.

What Is an Empty Plot? (Why This Works)

An empty plot is simply a plot without any data. The standard format for a plot function is plot(x, y, xlab, ylab, xlim, ylim). Within this format, x and y are the data points, xlab and ylab are the axis labels, and xlim and ylim are the value limits of each axis. To create a plot without any data you eliminate the data reference with the format of plot(1, type = “n”, xlab, ylab, xlim, ylim). The results of this second format can be a plot with axis labels and scales but no data. Creating a blank graph this way allows you to have a graph that is all set up but empty of data.

Graphs in the Absence of Data

Normally a graph would have data points, but an empty graph would not have any. An absence of data will result in an error message, which is why the two new arguments are needed in place of the data. Consequently, the minimal version of a plot function that produces a blank graph has the format of plot(1, type = “n”). This format produces a blank graph with default axis labels and scales. Including the axis labels and limits allows you to set these for yourself. This is important because there are seldom any circumstances where you want the default values.

Examples of the Method in Action

Here are three examples that illustrate how to produce empty plots. They each illustrate different aspects of the process from no axis labels to detailed axis labels.

> plot(1, type = “n”,
+ xlab = “”, ylab = “”,
+ xlim = c(0, 10), ylim = c(0, 10))

This example of an empty plot Illustrates creating one without any axis labels. It does so by equating the axis label parameters to blanks.

> plot(1, type = “n”,
+ xlab = “X”, ylab = “Y”,
+ xlim = c(0, 50), ylim = c(0, 20))

This example shows how to produce an empty graph that has simple axis labels. In this case, we simply equate the axis labels as “X” and “Y”.

> plot(1, type = “n”,
+ xlab = “X Axis”, ylab = “Y Axis”,
+ xlim = c(0, 100), ylim = c(0, 30))

This example produces more complex labels on a blank graph. In this case, we simply equate the axis labels as “X Axis” and “Y Axis”.

When / Where To Use This?

There are several reasons why you would want to create an empty graph. One of them is to produce a graph in the same style as one produced by R Studio but you can hand plot the graph yourself. One reason for doing this is for illustrating to an audience what is going on with a particular graph. A second application is to produce an example of a graph that you will be creating in R Studio before you add the data. A final application would be to produce a graph for which there is no data, but is still being used as an illustration of how the data should look.

At first, glance producing an empty plot may seem useless, but it has surprisingly interesting applications. If you need to produce a plot that does not have any data, it is an easy process and now you have the tools to do it.

Scroll to top