Small-caps in R legend?
Asked Answered
K

2

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}}

Kursh answered 16/6, 2011 at 9:30 Comment(3)
actually never seen real small caps in R, maybe tolower() respectively example(tolower) might help.Mamba
Yeah, plotmath gives everything: bold, greek etc, but not small-caps. Will try your suggestion.Kursh
I don't think tolower is going to help (having now tried it out). I need a mix of caps and small-caps in the legend (see edited question).Kursh
J
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

Junna answered 16/6, 2011 at 11:22 Comment(2)
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. :)Kursh
I could not find appropriate Unicode symbols for small numbers :/Junna
O
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)

Oscar answered 8/12, 2018 at 15:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.