rnorouzian
rnorouzian

Reputation: 7517

How to enlarge ONLY a letter of a word in R

Background:

It often happens that when you plot an equation consisting of letters (e.g., t), parentheses and numbers, some letters look much smaller than parentheses and numbers.

Question:

I'm wondering if there is a way in R to magnify (enlarge) only the letter "t" in my R code below to overcome the problem I described in the Background (see my R code below)?

enter image description here

Here is my R code:

par(family = "serif")
plot(1:10, ty='n')

mtext(bquote(italic("t")*(.(11))*" = "*.(2.78)* ",  "*italic("p")*" = "*.(.032)*",  
"*italic("d")*" = "*.(.66)*",  " *"95% "*CI[~italic((d))]* " ["*.(.42)*",  "* .(1.23)*"]" ) 
, side = 1, line = -15, at = 2, adj = 0, cex = 1.5)

Upvotes: 1

Views: 159

Answers (3)

IRTFM
IRTFM

Reputation: 263451

You can do it with mtext by enlarging everything with cex and then reducing the size of all the expression after the "t":

mtext(bquote(italic("t")*scriptscriptstyle( (.(11))*" = "*.(2.78)* ",  "*italic("p")*" = "*.(.032)*",  
"*italic("d")*" = "*.(.66)*",  " *"95% "*CI[~italic((d))]* " ["*.(.42)*",  "* .(1.23)*"]" ) )
, side = 1, line = -15, at = 2, adj = 0, cex = 3)

Upvotes: 0

d.b
d.b

Reputation: 32548

You can use text instead of mtext. One advantage is that if you had to enlarge some other letter in the middle, you can split the whole text into two groups and use strwidth to find out the position of the letter you want to enlarge. In this case, since the letter you want to enlarge is at the beginning, you can just write the whole text in just two steps. First write the longer text at certain x an y with and then write the text at the beginning with appropriate adj and cex. Read about adj at ?text.

graphics.off()
par(family = "serif")
plot(1:10, ty='n')

text(x = 2, y = 6, labels = bquote(italic("")*(.(11))*" = "*.(2.78)* ",  "*italic("p")*" = "*.(.032)*","*italic("d")*" = "*.(.66)*",  " *"95% "*CI[~italic((d))]* " ["*.(.42)*",  "* .(1.23)*"]" ), adj = 0, cex = 1.5)

text(x = 2, y = 6, labels = expression(italic("t")), adj = c(1, 0.2), cex = 5)


To demonstrate what I meant by being able to enlarge letters in middle, here's an example where I enlarged "p" in the middle

graphics.off()
windows(width = 8, height = 6, pointsize = 10)
par(family = "serif")
plot(1:10, ty='n', asp = 1)

text(x = 1, y = 6, labels = bquote(italic("t")*(.(11))*" = "*.(2.78)* ",  "), adj = 0, cex = 1.5)

w1 = strwidth(bquote(italic("t")*(.(11))*" = "*.(2.78)* ",  "), cex = 1.5)

text(x = 1+w1, y = 6, labels = bquote(italic("p")), adj = 0, cex = 5)

w2 = strwidth(bquote(italic("p")), cex = 5)

text(x = 1+w1+w2, y = 6, labels = bquote(" = "*.(.032)*","*italic("d")*" = "*.(.66)*",  " *"95% "*CI[~italic((d))]* " ["*.(.42)*",  "* .(1.23)*"]" ), adj = 0, cex = 1.5)

Upvotes: 3

r2evans
r2evans

Reputation: 160677

Since you are trying to change just the first letter, it can be relatively easy. Place the enlarged letter at the line/at and right-justified, and place the remainder of the string at the same line/at and left-justified.

par(family = "serif")
plot(1:10, ty='n')
at <- 1.5
line <- -4
mtext(bquote(italic("t")), side = 1, line = line, at = at, adj = 1, cex = 5)
mtext(bquote((.(11))*" = "*.(2.78)), side = 1, line = line, at = at, adj = 0, cex = 1.5)

enter image description here

Upvotes: 2

Related Questions