Can I create an empty ggplot2 plot in R?

df <- data.frame()
ggplot(df) + geom_point() + xlim(0, 10) + ylim(0, 100)

and based on @ilya's recommendation, geom_blank is perfect for when you already have data and can just set the scales based on that rather than define it explicitly.

ggplot(mtcars, aes(x = wt, y = mpg)) + geom_blank()

ggplot() + theme_void()

No need to define a dataframe.


Since none of the answers explicitly state how to make a plot that consists only of a label, I thought I'd post that, building off the existing answers.

In ggplot2:

ggplot() +
    theme_void() +
    geom_text(aes(0,0,label='N/A')) +
    xlab(NULL) #optional, but safer in case another theme is applied later

Makes this plot:

enter image description here

The label will always appear in the center as the plot window resizes.

In cowplot:

cowplot::ggdraw() +
    cowplot::draw_label('N/A')

ggdraw() makes a blank plot while draw_label draws a lable in the middle of it:

enter image description here

Tags:

R

Ggplot2