Set different fonts for line fragments in R

I have a long line txtthat I want to display as text in a field in a graph using mtext(). A string txtconsists of another string txt.sub, as well as a date string that applies a specific format to the argument to the date command. However, I want to display the "date" part of this line in bold only.

Line:

 date.in = as.Date( commandArgs( trailingOnly=TRUE )[1], format="%m/%d/%Y" )
 date = format(date.in, "%b %d, %Y")
 txt.sub = "Today date is: "
 txt = paste(txt.sub, date, sep = "") 

I tried the following

 ## Plot is called first here.
 mtext(expression(paste(txt.sub, bold(date), sep = "")), line = 0, adj = 0, cex = 0.8)

but the problem is that it does not insert values txt.suband date, but rather displays literally the words "txt.sub" and "date".

Is there a way to get the result I'm looking for? Thanks!

+4
source share
1 answer

(. " " " " ):

mtext(bquote(.(txt.sub) ~ bold(.(date))), line=0, adj=0, cex=0.8)
+5

All Articles