[R] Adding a title to a plot

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Thu Mar 4 18:30:07 CET 2021


On 04/03/2021 8:41 a.m., DY Kim wrote:
> Greetings!
> 
> I am currently using R x64 4.0.4.
> 
> I used the box-cox power transformation to create a range of lambdas and
> log-likelihood values using the equation.
> 
> b1=boxcox (DV ~ IV1 + IV2, data= newdata)
> 
> The above codes automatically created a plot with lambdas and
> log-likelihood values.
> 
> I want to add a main and subtitle to the plot. Would you please provide me
> with codes? Any help would be appreciated. Thank you.

The MASS:::boxcox.default method doesn't support adding a title.  If you 
want one, you'll have to edit the function to put in a title in the call 
to plot().  For example:

   boxcox.default <- MASS:::boxcox.default
   fix(boxcox.default)

and then edit this line

   plot(xl, loglik, xlab = xlab, ylab = ylab, type = "l",
             ylim = range(loglik, lim))

to

   plot(xl, loglik, xlab = xlab, ylab = ylab, type = "l",
             ylim = range(loglik, lim), main = "My title")

and save the result.  (You could make a slightly more sophisticated 
change such as adding "main" as an argument to the function, and using 
"main = main" in the call to plot(). )

Duncan Murdoch



More information about the R-help mailing list