cryptic0
cryptic0

Reputation: 245

Use italic font for selected text in textxy()

I am using calibrate library to place text in an xy plot and would like to change font for certain parts of the text. In the example below, I would like for 'K' to have italic font and the rest of the text in normal font.

textxy(7.5, 6, 'Arrows indicate optimal K', cx=0.8)

Upvotes: 0

Views: 585

Answers (1)

Gavin Simpson
Gavin Simpson

Reputation: 174843

You need a plotmath expression and to make use of the italic() plotmath function, e.g.:

textxy(7.5, 6, expression("Arrows indicate optimal" ~ italic(K)), cx=0.8)

or

textxy(7.5, 6, expression(Arrows~ indicate ~ optimal ~ italic(K)), cx=0.8)

Here is a full example:

require("calibrate")
plot(1:10, type = "n")
textxy(5, 5, expression("Arrows indicate optimal" ~ italic(K)), cx=0.8)

enter image description here

Upvotes: 1

Related Questions