# NOT RUN {
old = setwd(tempdir())
### Enable pdf() to draw Chinese characters nicely ###
### Requires the simkai.ttf font file, usually ###
### installed in Windows ###
## First, open the device
pdf("showtext-ex1.pdf")
## For now we are using the original device functions to draw axis labels
plot(1, type = "n")
## Then turn showtext on and draw some characters
showtext_begin()
text(1, 1.2, intToUtf8(c(21315, 31179, 19975, 36733)), cex = 5)
## Use another font
if("simkai.ttf" %in% font_files()) font_add("kaishu", "simkai.ttf")
text(1, 0.8, intToUtf8(c(19968, 32479, 27743, 28246)),
cex = 5, family = "kaishu")
## Turn showtext off
showtext_end()
## Also turn off the device
dev.off()
### Download font file from web ###
download.file("http://fontpro.com/download-family.php?file=36289",
"newrocker.ttf", mode="wb")
download.file("http://fontpro.com/download-family.php?file=35128",
"cutetumblr.ttf", mode ="wb")
font_add("newrocker", "newrocker.ttf")
font_add("cutetumblr", "cutetumblr.ttf")
png("showtext-ex2.png", 800, 500)
plot(1, type = "n")
showtext_begin()
text(1, 1.2, "Let me tell you a story", cex = 4, family = "newrocker")
text(1, 0.8, "Long long ago...", cex = 4, family = "cutetumblr")
showtext_end()
dev.off()
setwd(old)
# }
Run the code above in your browser using DataLab