waiver() function/argument in ggtitle() function

Hey everyone, beginner to R. Can someone explain to me what the waiver() function in labs() and ggtitle() does and can you show me a simple example with it (in the tidy verse syntax). Thank you.

Documentation shown on help tab:

Screenshot 2024-05-06 at 11.41.01 AM

From the point of view of a user, it looks like a filler. To a programmer I assume it has an important function in setting up a way to deal with text.



in practice, you never have to assign a parameter of a ggplot2 function a value of waiver()

a <- labs(title = waiver(),
     subtitle = "This is the subtitle"

b <- labs(subtitle = "This is the subtitle")

identical(a, b)

[1] TRUE
1 Like

Why simply not include the title and just move on to the subtitle? Is it because you NEED title as one of the arguments in the labs function, but in case you don't want to give your graph a title, you can just "waiver" it? Is that the reason for the waiver argument?

No you don't need it. Just omit it.

 labs(title = waiver()

is not doing anything. It is not doing any harm but it appears redundent.

1 Like

Okay so basically it's just for the user, or whoever is reading the code, to explicitly point out and understand that there is no title. Correct?

Sounds right, at least from the user's point of view.

1 Like

A waiver object.

Source: R/utilities.R

A waiver is a "flag" object, similar to NULL, that indicates the calling function should just use the default value. It is used in certain functions to distinguish between displaying nothing (NULL) and displaying a default value calculated elsewhere (waiver())