Search code examples
raxisdirectionggvis

Change axis direction


How to change axis direction in ggvis plot?

For example, y-axis. I want an origin to be on left top of the graph (I already put my x-axis to the top by putting orient ="top").

data %>% 
  ggvis(~XX, ~YY) %>% 
  layer_points() %>% 
  add_axis("y", title = "Y title") %>% 
  add_axis("x", title = "X title", orient ="top")

Solution

  • I believe you need the scale_numeric argument with reverse = TRUE to flip the order of the range.

    Below is an example based on the mtcars dataset.

    library(ggvis)
    mtcars %>% ggvis(~wt, ~mpg) %>%
      layer_points() %>%
      add_axis("x", orient = "top") %>%
      scale_numeric("y", reverse = TRUE)
    

    enter image description here