Dambo Dambo - 2 months ago 12
R Question

How to prevent ggvis from showing html encoding for special characters?

I have this a chart with

&
in a variable, I do I prevent ggvis from replacing
&
with its html code on the x-axis label?

library(dplyr)
library(ggvis)
data.frame(x="& label", y=10) %>%
ggvis(~x, ~y) %>%
layer_bars()

Answer

Got it! The regular ampersand won't work but the "full width" version does using C/C++/Java source code unicode format:

title <- "\uFF06"
mtcars %>% ggvis(x = ~wt, y = ~mpg, fill = ~cyl) %>%
  layer_points() %>%
  add_legend("fill", title = "Cylinders")  %>%
  add_axis("x",title=title)

enter image description here

http://www.fileformat.info/info/unicode/char/ff06/index.htm

Note that the "regular" ampersand character I was talking about that won't work is unicode \u0026

Comments