I would like to add a text to my plot so that one letter, a, appears bold. I started with the following, but the result is not what I need:
plot(1:5,axes=F)
mtext(c(only a should be bold),1:1,font=2)
What should I do to make only a bold?
Complex text editing can be done with expression. See ?plotmath for a list of commands.
mtext(expression(paste("only ", bold("a"), " should be bold")), 1, 1)
Related
I need to concatenate two strings within an R object: one is just regular text; the other is italicized. So, I tried a lot of combinations, e.g.
paste0(" This is Regular", italic( This is Italics))
The desired result should be:
This is Regular This is Italics
Any ideia on how to do it?
Thanks!
In plot labels, you can use expressions, see mathematical annotation :
plot(1,xlab=expression("This is regular"~italic("this is italic")))
To provide an string for which an HTML parser will recognise the need to render the text in Italics, wrap the text in <i> and </i>. For example: "This is plain text, but <i>this is in Italics</i>.".
However, most HTML processors will assume that you want your text to appear as-is and will escape their input by default. This means that the special meanings of certain characters - including < and > will be "turned off". You need to tell the processor not to do this. How you do that will depend on context. I can't tell you that because you haven't given me context.
Are you for example, writing to a raw HTML file? (You need do nothing.) Are you writing to a Markdown file? If so, how? In plain text or in a rendered chunk? Are you writing a caption to a graphic? (Waldi has suggested a solution.) Etc, etc....
I need to present in bold the text
xyz:abc:01******-*.***
by RestructuredText syntax. Could you help me?
Thank you
In general you could use a backslash character ("\"r) in front of characters which have a particular meaning in reStructuredText different from beeing "just a character". If you want to display asterisks in you text just user "\*".
The text from your example above should be then
xyz:abc:01\*\*\*\*\*\*-\*.\*\*\*
I want to the following text to appear on a heatmap.3 key "value": (\n to allow start on second line) Log2 Fold Change
Using the following code, I got this: Log[2] Fold Change:
paste0("\n", expression(Log[2])," Fold Change")
The newline worked and the text started started on the second line as required. But, how can I get rid of the []
expression part should be before paste; like here:
expression(paste("\n", Log[2], " Fold Change")) -> text
plot(1:10, xlab=text)
I've learned to apply bold to a portion of the text used in a plot title using mtext() expression() and paste(). This works great if you specify the strings outright. However, in the project I'm working on now, the portion of text to be bolded needs to be obtained through a call to an element of a vector. However, the characters needed in the call syntax are interpreted by expression() and the call fails.
junk <- c("I'm Special", "You're Special")
plot(0, type="n")
mtext(expression(paste("Do you think ", bold(junk[1]),"today?")),3,2)
mtext(expression(paste("I think ", bold(junk[2]), "today.")),3,1)
Any thoughts on how to approach this? I am trying to avoid specifying the bold text directly.
bquote has a decent interface for this. You just surround the variable you want to substitute with .(). You could also use substitute with expression.
junk <- c("I'm Special", "You're Special")
plot(0, type="n")
mtext(bquote(paste("Do you think ", bold(.(junk[1])),"today?")),3,2)
mtext(bquote(paste("I think ", bold(.(junk[2])), "today.")),3,1)
I wish to print a text in the title in two lines but am not able to achieve desired output because of subscript present in the text. Following is the e.g of the text that I want in two lines.
plot(1,main=expression(paste(CO[2]~'Flux (kg C ', m^-2,' ',s^-1,')')))
BUT using line break as in following command does not give desired result of bringing (only) the text following it in new line:
plot(1,main=expression(paste(CO[2]~'Flux \n(kg C ', m^-2,' ',s^-1,')')))
Please help me with this issue.
Thanks in advance
You can do this with the atop function.
plot(1,main=expression(atop(CO[2]~'Flux', paste('(kg C ', m^-2,' ',s^-1,')'))))
Since the lheight par doesn't affect expressions, if you want tighter spacing between the lines, you can use the following.
plot(1,main=expression(textstyle(atop(CO[2]~'Flux', paste('(kg C ', m^-2,' ',s^-1,')')))),
cex.main=2)