Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot 32 bit unicode characters? R 3.2.2 hangs on Windows/RStudio

Tags:

r

unicode

rstudio

How can I plot unicode symbols like the 🚺 WOMENS SYMBOL or the 🚹 MENS SYMBOL, or other symbols from that codeblock? Apart from setting a font family that contains those characters, R hangs on my system* when using the point character pch like that:

plot(0, type="n")
points(1, .5, pch=-0xfffdL)
# works
points(1, -.5, pch=-0x1f6b9L)
# R hangs

As the doc states,

Where supported by the OS, negative values specify a Unicode code point, so e.g. -0x2642L is a ‘male sign’ and -0x20ACL is the Euro.

*My sessionInfo():

R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] rsconnect_0.3.79 tools_3.2.2 

Thanks for help & checking on your system in advance.


Edit: Windows hangs when I use RStudio 0.99.879 with the RStudio graphics device. If I use dev.new(noRStudioGD=T) explicitly, then I get a smiliar error as mentioned in the comments: "Error in plot.xy(xy.coords(x, y), type = type, ...) : invalid input '🚹' in 'utf8towcs'". For now, I'll use the PNG fallback option as mentioned by @42-.

like image 676
lukeA Avatar asked Apr 11 '16 19:04

lukeA


1 Answers

I don't have an answer but there are some public domain versions in png format:

enter image description here enter image description here

You should be able to shrink these and print at desired locations: using custom images instead of standard shapes for R line chart markers

library(png)
img <- readPNG('~/Downloads/mens_room_clip_art_9332/Mens_Room_clip_art_small.png')
str(img)
# num [1:100, 1:100, 1:4] 1 1 1 1 1 1 1 0 0 0 ...
require(grid)
#Loading required package: grid
male <- rasterGrob(img)
img <- readPNG('~/Downloads/ladies_room_clip_art_16926/Ladies_Room_clip_art_small.png')
female <- rasterGrob(img)

df = data.frame(x=rep(1:4,2), y=c(1,1,2,4,6.5,5,5.5,4.8), g=rep(c("s","m"),each=4))
p = ggplot(df, aes(x, y, group=g)) + 
  geom_line() +
  theme_bw()

a=0.2
for (i in rownames(df[df$g=="s",])) {
  p = p + annotation_custom(male, df[i,"x"]-a,df[i,"x"]+a,df[i,"y"]-a,df[i,"y"]+a)  
}

b=0.2
for (i in rownames(df[df$g=="m",])) {
  p = p + annotation_custom(female, df[i,"x"]-b,df[i,"x"]+b,df[i,"y"]-b,df[i,"y"]+b)  
}
png();print(p);dev.off()

enter image description here

I also took the images and pasted into Gimp and scaled to 24 pixels:

enter image description hereenter image description here

like image 171
IRTFM Avatar answered Oct 21 '22 18:10

IRTFM