[r] How to draw an empty plot?

I need to make an empty plot. This is the best could I come up with.

plot(0, xaxt = 'n', yaxt = 'n', bty = 'n', pch = '', ylab = '', xlab = '')

Any simpler solutions?

P.S.: completely empty, no axis etc.

This question is related to r ggplot2 plot

The answer is


The following does not plot anything in the plot and it will remain empty.

plot(NULL, xlim=c(0,1), ylim=c(0,1), ylab="y label", xlab="x lablel")

This is useful when you want to add lines or dots afterwards within a for loop or something similar. Just remember to change the xlim and ylim values based on the data you want to plot.

As a side note: This can also be used for Boxplot, Violin plots and swarm plots. for those remember to add add = TRUE to their plotting function and also specify at = to specify on which number you want to plot them (default is x axis unless you have set horz = TRUE in these functions.


I suggest that someone needs to make empty plot in order to add some graphics on it later. So, using

plot(1, type="n", xlab="", ylab="", xlim=c(0, 10), ylim=c(0, 10))

you can specify the axes limits of your graphic.


If anyone is looking for a ggplot2 solution, you can use either cowplot or patchwork packages

library(ggplot2)

### examples from cowplot vignettes
plot.mpg <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) +
  geom_point(size = 2.5)
plot.diamonds <- ggplot(diamonds, aes(clarity, fill = cut)) + 
  geom_bar() +
  theme(axis.text.x = element_text(angle = 0, vjust = 0.5))

library(cowplot)
### use NULL
plot_grid(plot.mpg, NULL, NULL, plot.diamonds,
  labels = c("A", "B", "C", "D"),
  ncol = 2
)

# Note: if you want to initialize an empty drawing canvas, use ggdraw() 

library(patchwork)
### use plot_spacer()
plot.mpg + plot_spacer() + plot_spacer() + plot.diamonds +
  plot_layout(ncol = 2) +
  plot_annotation(
    title = "Plot title",
    subtitle = "Plot subtitle",
    tag_levels = "A",
    tag_suffix = ")"
  )

Created on 2019-03-17 by the reprex package (v0.2.1.9000)


grid.newpage() ## If you're using ggplot

grid() ## If you just want to activate the device.

Adam, following your comment above ("I wanted the empty plot to serve as filler in a multiplot (mfrow) plot."), what you actually want is the mfg option

    par(mfg=c(row,column))

- which controls where you want to put the next plot. For instance, to put a plot in the middle of a 3x3 multiplot, do

    par(mfrow=c(3,3))
    par(mfg=c(2,2))
    plot(rnorm(10))

This is marginally simpler than your original solution:

plot(0,type='n',axes=FALSE,ann=FALSE)

You need a new plot window, and also a coordinate system, so you need plot.new() and plot.window(), then you can start to add graph elements:

plot.new( )
plot.window( xlim=c(-5,5), ylim=c(-5,5) )

points( rnorm(100), rnorm(100) )
axis( side=1 )

example plot


An empty plot with some texts which are set position.

plot(1:10, 1:10,xaxt="n",yaxt="n",bty="n",pch="",ylab="",xlab="", main="", sub="")
mtext("eee", side = 3, line = -0.3, adj = 0.5)
text(5, 10.4, "ddd")
text(5, 7, "ccc")

There is an interest in your solution that plot.new() hasn't though: in the empty plot you "draw" you can write text at specified coordinates with text(x = ..., y = ..., your_text).


Examples related to r

How to get AIC from Conway–Maxwell-Poisson regression via COM-poisson package in R? R : how to simply repeat a command? session not created: This version of ChromeDriver only supports Chrome version 74 error with ChromeDriver Chrome using Selenium How to show code but hide output in RMarkdown? remove kernel on jupyter notebook Function to calculate R2 (R-squared) in R Center Plot title in ggplot2 R ggplot2: stat_count() must not be used with a y aesthetic error in Bar graph R multiple conditions in if statement What does "The following object is masked from 'package:xxx'" mean?

Examples related to ggplot2

Center Plot title in ggplot2 R ggplot2: stat_count() must not be used with a y aesthetic error in Bar graph Saving a high resolution image in R Change bar plot colour in geom_bar with ggplot2 in r Remove legend ggplot 2.2 Remove all of x axis labels in ggplot Changing fonts in ggplot2 Explain ggplot2 warning: "Removed k rows containing missing values" Error: package or namespace load failed for ggplot2 and for data.table In R, dealing with Error: ggplot2 doesn't know how to deal with data of class numeric

Examples related to plot

Fine control over the font size in Seaborn plots for academic papers Why do many examples use `fig, ax = plt.subplots()` in Matplotlib/pyplot/python Modify the legend of pandas bar plot Format y axis as percent Simple line plots using seaborn Plot bar graph from Pandas DataFrame Plotting multiple lines, in different colors, with pandas dataframe Plotting in a non-blocking way with Matplotlib What does the error "arguments imply differing number of rows: x, y" mean? matplotlib get ylim values