ggvis中的轴文本偏移

Axis text offset in ggvis

一个简短而快速的问题,有没有办法偏移轴上的文本(不是标题文本),因为我使用相当大的 x-axis(以一定角度对齐) 90) 一些文字背后的情节...

这是我的代码的轴部分::

add_legend("fill", title = "Score") %>%
  add_axis("x", orient = 'top', title = "Sample",title_offset=50,properties=axis_props(labels = list(angle=-90, fontSize=6))) %>%
  add_axis("y", orient = 'right', title = "Class")

是的,您需要为此使用 tick_padding 参数。我提供了一个例子,因为我无法重现你的情节。

没有偏移:

library(ggvis)
mtcars %>% ggvis(~mpg, ~wt) %>% layer_points() 

这是 tick_padding(偏移量以像素为单位):

mtcars %>% ggvis(~mpg, ~wt) %>% layer_points() %>%
  add_axis("x", tick_padding=20)