Empty dataset for ggplot



can anybody direct me. I need to create a figure with an imaginary output (without using a separate datafile). SO I was first thinking how to simply create axis and name them, just a graph without any actual data plots. However all the examples for beginners are always with a dataset in it. Can I create a graph with ggplot without using a dataset?


You definitely can! geom_blank is your friend:


ggplot() +

That'll get you a big, grey nothing. Then you can add some scales:

ggplot() +
  geom_blank() +
  scale_x_continuous(limits = c(1, 5), name = 'Best. X axis. Ever.') +
  scale_y_continuous(limits = c(10, 20), name = 'This Y axis could use some work...') +
  ggtitle('Ta-da!', subtitle = 'A work of art!')

Hope that helps!


Thank you so so much!

I have been trying to move onwards for a day and could not figure this out and was starting to feel frustrated. I thought that I MUST put something in the brackets of ggplot (), so I would always omit the dataset and continued with aes(), which would always give me an error message. Now even the ggplot() + geom_blank() feels like I am moving onwards. Thanks a ton!


No worries! I know what it's like to feel the mixture of relief and frustration when you've been banging your head against the wall on something for a few days and then you reach out and someone helps with it quickly :sweat_smile:

EDIT: as a side note, you don't need to supply aesthetics in the ggplot call even if you provide a dataset—you can instead choose to provide them to the individual geoms (although you'll have to make sure that they each get the aesthetics they need if there are several geoms). The ones in the ggplot call get passed on to all of the geoms, but as long as each geom ends up with the ones it requires, it should all be gravy. In this case, geom_blank doesn't require any aesthetics, so you don't need any anywhere :slight_smile:


Exactly! Especially when you know it is nothing too complex, but you just lack any ground what so ever, that you cannot even google it properly :D. Thanks again.