0

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")
zx8754
  • 52,746
  • 12
  • 114
  • 209
Olya
  • 25
  • 1
  • 4
  • 2
    Please share some code to illustrate what you're trying to achieve. – mtoto Mar 23 '16 at 13:18
  • I want my y-axis to start at the left top and increase to the bottom (basically, to change y-axis direction) `data %>% ggvis(~XX, ~YY) %>% layer_points() %>% add_axis("y", title = "Y title")%>% add_axis("x", title = "X title", orient ="top")` – Olya Mar 23 '16 at 13:24
  • Welcome to Stack Overflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – zx8754 Mar 23 '16 at 13:34

1 Answers1

1

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

mtoto
  • 23,919
  • 4
  • 58
  • 71
  • Thanks! That is exactly what I was looking for! – Olya Mar 23 '16 at 13:32
  • No problem, and welcome to SO! Please make sure to post [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) questions in the future, that makes it easier for others to help you. – mtoto Mar 23 '16 at 13:34