我正在尝试使用layer_text()将unicode文本添加到图形中,但除非我将文本作为常量提供,否则它不起作用:
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)
有没有解决方案?
与locale相关的sessionInfo的摘录:
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
答案 0 :(得分:1)
运行以下代码(通过RStudio)对我有用:
library(dplyr)
library(ggvis)
x <- data.frame(a=c(1, 2), b=c("\u2799", "\u2794"))
x %>% ggvis(~a) %>% layer_text(text := ~b)
这对我也有用:
y <- data.frame(a=c(1, 2), b=c("➙", "➔"))
y %>% ggvis(~a) %>% layer_text(text := ~b)
以下是截图:
以下是我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
所以显而易见的问题是:你的设置有什么不同?