How to create an empty plot using ggplot2 in R?


The two most easy ways to create an empty plot using ggplot2 are using geom_blank function and also adding the theme_bw along with the geom_blank. The geom_blank will create an empty plot with white gridlines and grey background, on the other hand, addition of theme_bw will create the empty plot with grey gridlines and white background.

Example

Consider the below data frame:

Live Demo

> set.seed(151)
> x<-rnorm(20)
> y<-rnorm(20,1,0.5)
> df<-data.frame(x,y)
> df

Output

      x         y
1  -0.05153895 0.3139643
2   0.76573738 0.1816184
3  -0.14673959 0.8201743
4  -0.11318581 1.6005576
5  -0.39551140 0.6770630
6  0.78227595 0.7446956
7  -1.39747811 0.7004385
8  -1.01883832 1.2728014
9   0.22947586 0.7543531
10  0.67217297 1.0957678
11 -0.48455178 0.7207362
12  0.56060896 1.4613498
13  0.06615648 1.5769990
14 -1.34987612 0.3137949
15 -0.24291581 1.6450906
16 -1.23674102 1.5774510
17 -1.47467765 1.7228397
18  2.43715892 1.1305064
19  0.67352581 1.9645730
20  0.31003951 0.7000570

Loading ggplot2 package and creating an empty plot with grey background:

Example

> library(ggplot2)
> ggplot(df,aes(x,y))+geom_blank()

Output:

Creating an empty plot with white background:

Example

> ggplot(df,aes(x,y))+geom_blank()+theme_bw()

Output:

Updated on: 21-Nov-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements