2
votes

I'm all new to R, and the rgl packageand having searched all over all day for a solution...

I'm trying to use rgl's text3d function with unicode text. I have no problem plotting the same chars in 2D (using text()), but in 3D, instead of rendering the symbols it just writes out the UTF-8 char codes (unless they're ascii chars).

I'm reading in data from file where the column "vowel" contains the symbols to be plotted (e.g. "e i ə ɪ ɒ" etc.), and cols "F1", "F2" and "F3" contain the values to be plotted. The file is read in with read.delim with encoding="UTF-8"; and inspecting the data in the RGui shows the UTF-8 char codes for any non-ascii symbols.

Sample data (comma-delimited)

vowel,F1,F2,F3
i,424.1352452,1985.143387,2549.272611
e,515.0401373,1693.077496,2534.527142
ə,408.8233704,1589.12993,2567.448424
ɒ,490.6565129,1070.564989,2590.467597
ɪ,405.5223379,1665.733731,2261.069994
u,360.0803517,1798.355786,2354.845875
ɜ,541.6360766,1323.593646,2435.121753
ɑ,718.8871543,1139.013741,2820.694337
ɑ,629.1691413,1064.047107,2910.997552
ɪ,375.0097039,2091.996102,2648.991664

This is the code I've been testing with:

d <- read.delim("my.filename", header=TRUE, sep=",", encoding="UTF-8")

Plotting in 3D (plots things like "<\U+0252>" etc. (escaped here!) for all non-ASCII chars):

library(rgl)

cols <- c("F1", "F2", "F3");
plot3d(d[,cols], xlab="F1", ylab="F2", zlab="F3", type="n");
text3d(d[,cols], col=1, text=d$vowel);

Plotting in 2D (works):

cols <- c("F1", "F2");
plot(d[,cols], xlab="F1", ylab="F2", type="n");
text(d[,cols], col=1, labels=d$vowel);

Does it have something to do with OpenGL? I've installed freetype, hoping that might solve the issue, but I haven't managed to point R to it - so it issues warnings "par3d(useFreeType = TRUE) : FreeType not supported in this build" and "In par3d(useFreeType = TRUE) : font family "sans" not found, using "bitmap""...

Having spent several hours battling R for freetype, I was hoping someone here can tell me whether freetype will even solve the issue??! If yes, a hint as to what "Set the environment variable LIB_FREETYPE to give the full path to the install directory" (from rgl README) is trying to tell me to do would be hugely appreciated!

Thank you.

My sessionInfo:

R version 3.0.2 (2013-09-25) Platform: x86_64-w64-mingw32/x64 (64-bit)

locale: LC_COLLATE=English_United Kingdom.1252
LC_CTYPE=English_United Kingdom.1252
LC_MONETARY=English_United Kingdom.1252
LC_NUMERIC=C
LC_TIME=English_United Kingdom.1252

attached base packages: stats graphics grDevices utils datasets methods base

other attached packages: rgl_0.93.975

1
A minimal reproducible example would be appreciated. You've given us a fragment of your code but not the data behind it, so we can't do any more than guess as to the nature of the problem. Please read this post then edit your question to include some of your data, or made-up data.SlowLearner
Thanks, I've added some sample data. Sorry I didn't before, thought the description of it was enough since it's so basic!crs
We like cut n paste examples, which you've almost done. Saves us a LOT of bother.Spacedman
For what its worth your example works fine for me with the same rgl and R, but on Linux. By default I get par3d()$useFreeType set TRUE (dont ask me how, it just is) but if I set it to FALSE I get text 3 contains unsupported character.Spacedman
Thanks, Spacedman. I'm still trying to figure out how! I'm so desperate I posted it as a new question (stackoverflow.com/questions/19326234/…)crs

1 Answers

1
votes

You need to have FreeType installed. Make sure you have FreeType and FreeType Open GL libraries installed, then reinstall rgl in R and then everything works.

See here also : http://www.smnd.sk/kotanyi/index.php?page=rgl