8

This is a simple question.

I am trying to write a legend with text in small caps in R.

I can write the plot using tikzDevice and manually change the plot to small-caps in LaTex, but I want to know if it's possible in R itself?

Thanks.

This is the R code I am using so far:

legend("bottomright", inset=.05, c(expression(Delta*ZRT1), expression(Delta*ZRT2)), lty=1:2, pch=1:2)

This is the LaTex expression I am trying to get into the R legend:

\Delta Z\textsc{rt\oldstylenums{1}}

Frank Zafka
  • 829
  • 9
  • 30

2 Answers2

5

The Unicode standard does define a number of "small capital" characters in the IPA extensions. E.g., using this Smallcaps Generator: http://fsymbols.com/generators/smallcaps/

plot(1L:10, main="Aʙᴄᴅᴇғɢʜɪᴊᴋʟᴍɴᴏᴘǫʀsᴛᴜᴠᴡxʏᴢ")
legend("bottomright", expression(\Delta Zʀᴛ1")

enter image description here

As of Unicode 5.1, the only characters missing to allow representation of the full Latin alphabet in small capital Unicode characters are small capital versions of Q and X. See also here: http://en.wikipedia.org/wiki/Small_caps#Unicode

rcs
  • 67,191
  • 22
  • 172
  • 153
  • That's an interesting way of doing it. Thanks for the answer. Only problem is, for consistency, the 1 needs to be the same size as the small-cap. Otherwise, you certainly answered the question. :) – Frank Zafka Jun 16 '11 at 15:50
  • I could not find appropriate Unicode symbols for small numbers :/ – rcs Jun 16 '11 at 16:40
1

The small caps generated by Smallcaps Generator do not work for all fonts. For example, the Linux Libertine family (Libertine, Biolinum) have their small caps and Old Style numbers in the Unicode Private Use Area (E000-F8FF), as shown here (last page).

The example plots below use axis labels assembled from the small caps generator, plus the small_caps and small_nums string, assembled from the private use area. The first plot uses Times New Roman, which works with the generated small caps but does not have corresponding glyphs in the private use area. The second plot uses Linux Libertine O, which does not have all Unicode characters from the IPA extensions.

library(ggplot2)

x <- 1L:10
y <- 1L:10
df <- data.frame(x,y)

# assemble strings from Libertine's private use area.
small_caps <- "S\UE05D\UE051\UE05C\UE05C C\UE051\UE060\UE063"
small_nums <- "\UE020\UE021\UE022\UE023\UE024\UE025\UE026\UE027\UE028\UE029"

font <- "Times New Roman"
ggplot(df) +
  geom_point(aes(x = x, y = y)) +
  labs(x = paste("Sᴍᴀʟʟ Cᴀᴘs /", small_caps),
       y = paste("Oʟᴅ Sᴛʏʟᴇ", small_nums)) +
  theme(text = element_text(family = font)) +
  annotate("text", x = 2, y = 9, label = font)

font <- "Linux Libertine O"
ggplot(df) +
  geom_point(aes(x = x, y = y)) +
  labs(x = paste("Sᴍᴀʟʟ Cᴀᴘs /", small_caps),
       y = paste("Oʟᴅ Sᴛʏʟᴇ", small_nums)) +
  theme(text = element_text(family = font)) +
  annotate("text", x = 2, y = 9, label = font)

Created on 2018-12-08 by the reprex package (v0.2.1)

Michael S Taylor
  • 425
  • 5
  • 16