Search code examples
rggvis

Axis text offset in ggvis


A short and quick question, is there a way to offset the text in the axis (not the title text)enter image description here, as I use rather a large x-axis (aligned at an angle of 90) some of the text goes behind the plot...

here is the axis part of my code:::

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")

Solution

  • Yeah you need to use the tick_padding argument for this. I provide an example as I cannot reproduce your plot.

    Without an offset:

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

    enter image description here

    And this is with the tick_padding (the offset is measured in pixels):

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

    enter image description here