3

I make some plots with R and use bquote because I need variables for the main of the plot. However, the main is no longer bold but I want it to be bold. I defined the main as follows:

title = bquote(atop("Empirical Pricing Kernel at Date",~.(EndDate)~"with Index Price"~.(ST)~"€"))

plot(temp, EPK, type="l", main = title)

Enddate contains "2014-08-01" as date and ST is just numeric with 9210.08.

Is there any way to make it bold with or without bquote? I'd like to find a solution with bquote because it's very convenient when using subscripts.

My problem is that I am using it in a par-plot with two plots and the other plot needs no special things in it's main. So, the main is bold. I even tried to just put bquote around it in order to get the same font size but it stayed bold.

stats_guy
  • 695
  • 1
  • 9
  • 26
  • 1
    Are you only passing one parameter to `atop()`? Do you really need that? It doesn't look like you are using any `plotmath` here. Can't you just `paste()` the values? It would help if this example were actually [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so we knew exactly what was in each of the variables you refer to. – MrFlick Dec 15 '14 at 21:44
  • I edited the answer and added the content of the variables I am using. When I use paste, it doesn't give me the values of the variables. I need `atop` because I need a line break and without atop the lines are not properly centered. – stats_guy Dec 15 '14 at 21:54
  • The last couple of sentences made no sense to me, but I hope that the solution offered solves the problem and allows you to get a better handle on how to use expressions. – IRTFM Dec 15 '14 at 22:26

1 Answers1

6

I prefer to use what I think of as "pure plotmath" so I use tilde's instead of spaces and use no quotes. I suspect it was the leading tilde in the second argument to bquote that was throwing the error. In plotmath the tildes need something on either side: If you really need a none-displayed something you can always use phantom(0) but why bother in this case?

bquote(atop(Empirical~Pricing~Kernel~at~Date, 
            bold(.(EndDate))~with~Index~Price~.(ST)~"€"
       )   )

Test:

EndDate="2014-08-01";ST=9210.08
title = bquote(atop(Empirical~Pricing~Kernel~at~Date, bold(.(EndDate))~with~Index~Price~.(ST)~"€"))
   plot(1,1, type="l", main = title)

enter image description here

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Following the example of @42, would it be possible to make the variable `ST` bolditalic? I have tried wrapping `bolditalic(.(ST))` without success. Any idea? – Shepherd Aug 11 '17 at 13:09
  • I don't offhand see a reason for failure, since the "dot"-function should work within `plotmath`-functions. Saying "without success" is not particularly helpful in the debugging process. You need to describe the class of ST and the code you used. Perhaps you should submit a question with a [MCVE]. – IRTFM Aug 11 '17 at 16:48
  • Thank you for your reply. This is what I did: `EndDate="2014-08-01";ST=9210.08; title = bquote(atop(Empirical~Pricing~Kernel~at~Date, bold(.(EndDate))~with~Index~Price~bolditalic(.(ST))~"€")); plot(1,1, type="l", main = title)` However, the variable ST does not show as bold italic. – Shepherd Aug 11 '17 at 17:45
  • Oh. Now I remember. Numerics do no print with `bolditalic`. (See the `?plotmath` page.) Need to quote that decimal number. Should succeed then. – IRTFM Aug 11 '17 at 17:54
  • Thanks, now it works like this: `EndDate="2014-08-01";ST=9210.08; title = bquote(atop(Empirical~Pricing~Kernel~at~Date, bold(.(EndDate))~with~Index~Price~bolditalic("9210.08")~"€")); plot(1,1, type="l", main = title)` So it is not possible to change the value of `ST` dynamically (like in a `for` loop)? – Shepherd Aug 11 '17 at 18:47
  • If you loop over ST values and then apply `as.character`, possibly with `sprintf` or `formatC` to round or truncated trailing decimal places you don't wnat it should succeed. (This is really fairly far afield from the oritinal question. You should not be using comments for this.) – IRTFM Aug 11 '17 at 19:29