You can use a "text cursor" alongside grid
's functions for interrogating grobs
. Say you had the phrase: "I want this text bold!!!!!!!, and you want the exclamation points in red:
grid.text("I want ",
name="notboldtext",
hjust=0)
text.cursor<-convertWidth(grobWidth("notboldtext") # Adds textGrob width & to location
+ unit(.5, "npc"), "npc")
grid.text("this text bold",
x=text.cursor,
gp=gpar(fontface="bold"),
name="boldedtext",
hjust=0)
text.cursor<- text.cursor + convertWidth(grobWidth("boldedtext"), "npc")
grid.text("!!!!!!!",
gp=gpar(col="red"),
x=text.cursor,
name="maptextnat",
hjust=0)