3

is anyone here familiar with the 'Cobalt' package in R? I am trying to change the title of a balance plot (using bal.plot) and for some reason it's not taking the 'title' option. The default title Distributional Balance for "prop.score" is shown even when I try to customize.

My code is:

bal.plot(d, 
         var.name = "prop.score",
         which = "both",
         type = "density",
         mirror = TRUE,
         title = "Figure 1. Distributional Balance") + 
    theme_classic()

I thought it might be the theme_classic() but the problem persists regardless of whether that's included.

a_todd12
  • 449
  • 2
  • 12
  • Please read `?bal.plot`. – Henrik Aug 13 '22 at 12:28
  • Maybe I'm just a terrible reader, but the below quote is all I see on titles. And I am able to change a love.plot title successfully. "Like the output of bal.plot(), the output of love.plot() is a ggplot2 object, which means ggplot2 users can modify the plot to some extent for presentation or publication. Several aspects of the appearance of the plot can be customized using the love.plot() syntax, including [...] the title of the plot" – a_todd12 Aug 13 '22 at 17:48
  • Ahh, I can read, I'm just also an idiot. I added + labs(title = "") and, because the output is a ggplot object, I can manipulate it that way. Still not sure why the within-bal.plot title didn't work, but that's okay! – a_todd12 Aug 13 '22 at 17:57

1 Answers1

0

The solution is to just treat it like a ggplot object. Though I'm still not sure why my original code didn't work.

bal.plot(d, 
         var.name = "prop.score",
         which = "both",
         type = "density",
         mirror = TRUE) + 
    theme_classic() +
    labs(title = "Figure Title")
a_todd12
  • 449
  • 2
  • 12
  • `title` isn't an acceptable argument to `bal.plot()`. Does anything about the documentation suggest that it would be? – Noah Aug 30 '22 at 15:53
  • The text I included in a comment above (from the documentation) makes it seem like ```love.plot()``` and ```bal.plot()``` can be treated similarly, and ```love.plot()``` does seem to accept ```title``` so I figured (incorrectly) that ```bal.plot()``` would as well. – a_todd12 Aug 31 '22 at 11:51