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:
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:
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.
See
library(ggplot2)
?waiver
waiver
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
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.
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.
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()
)
waiver()
https://ggplot2.tidyverse.org/reference/waiver.html
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.