Avoiding: Warning: Vectorized input to `element_text()` is not officially supported.

I've used ggplot2 code like this for some time without any warnings to have a "left" and "right" caption:

. . .      +
  labs(caption=c(plotCaptionLeft, plotCaptionRight))        +
  theme(plot.caption = element_text(hjust=c(0.0,1.0)))

... which creates something like this:

In ggplot2_3.3.0 I'm seeing this warning now:

## Warning: Vectorized input to `element_text()` is not officially supported.
## Results may be unexpected or may change in future versions of ggplot2.

Should I ignore the warning until RStudio decides how a vectorized element_text() will work? Or is there a better way to code this now to avoid the warning?

1 Like

Multiple captions are not supported in ggplot2 (and never was), and your example only works accidentally. You can continue using it for as long as it works, but be aware that any update to ggplot2 may break it as we continually refine the internals

1 Like

you could achieve a similar effect by creating your own spacer.
Not ideal, because you find the space by tweaking and its only for a given plot size, still it works.


plotCaptionLeft <- "some text"
plotCaptionRight <-"more text"
spacer <- paste0(rep(" ",250),collapse="")

ggplot(mtcars) + 
  geom_point(aes(x = wt, y = mpg, colour = gear)) +
  labs(caption=paste0(plotCaptionLeft, spacer,plotCaptionRight))   +
  theme(plot.caption = element_text(hjust=0))

1 Like

Thanks for the reply, but the vectorized solution that works (accidentally) now is a much better solution than a spacer that may take several iterations to get right, and would likely require a different value for different fonts. With R a vector language, I don't understand why a vectorized solution hasn't already been implemented intentionally.

Plea from user here.

I am a frequent user of the ggsurvplot function in the survminer package. This function plots Kaplan-Meier curves, and does a really nice job with the risk table. Most journals require such a table, and the people I support are fussy about the table format. Unfortunately if there is more than one stratum the warning message appears. Turning off the message is easy, but my fear is that a change will be made to ggplot that will mess up the risk table.

Please, please, pretty please don't make an internal change that would mess up ggsurvplot. Hopefully you could coordinate with the developer of the survminer package.

3 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.