Small-caps in R legend?
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\te开发者_运维知识库xtsc{rt\oldstylenums{1}}
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")
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
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)
精彩评论