Search code examples
runicodeggvis

Adding unicode text to ggvis plot


I am trying to add unicode text to a graphic using layer_text(), but it does not work unless I supply the text as a constant:

x = data.frame(a=c(1,2),b=c("\\u2799","\\u2794"))

# This one works
x %>% ggvis(~a) %>% layer_text(text := "\\u2794")

# Now does not work
x %>% ggvis(~a) %>% layer_text(text := ~b)

# Nor this way
x = data.frame(a=c(1,2),b=c("\u2799","\u2794"))
x %>% ggvis(~a) %>% layer_text(text := ~b)

Is there any solution?

Excerpt of my sessionInfo related to locale:

R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252

Solution

  • Running the following code (through RStudio) works for me:

    library(dplyr)
    library(ggvis)
    x <- data.frame(a=c(1, 2), b=c("\u2799", "\u2794"))
    x %>% ggvis(~a) %>% layer_text(text := ~b)
    

    This also works for me:

    y <- data.frame(a=c(1, 2), b=c("➙", "➔"))
    y %>% ggvis(~a) %>% layer_text(text := ~b)
    

    Here is a screenshot:

    screenshot

    Here is a relevant excerpt of my sessionInfo()

    # R version 3.1.2 (2014-10-31)
    # Platform: x86_64-pc-linux-gnu (64-bit)
    # locale:
    # [1] LC_CTYPE=en_US.UTF-8
    # other attached packages:
    # [1] ggvis_0.4     dplyr_0.3.0.2
    

    So the obvious question is: what is different about your setup?