This is what i have so far with the ggvis package in R.
mtcars %>% ggvis(x = ~disp) %>%
layer_lines(y = ~wt, stroke := "red") %>%
layer_lines(y = ~mpg) %>%
add_axis("y", orient = "left", title = "Weight (lb/1000)") %>%
add_axis("y", orient = "right", title= "Miles/(US) gallon") %>%
add_axis("x", title = "Displacement (cu.in.)")
I cannot get the left Y axis to represent the wt scale data.
This outputs:
I assume you want the left y axis (i.e. wt) divided by 1000:
library(dplyr) #you need this library
mtcars %>% mutate(wt_scaled=wt/1000) %>% ggvis(x = ~disp) %>% #use mutate from dplyr to add scaled wt
layer_lines(y = ~wt_scaled, stroke := "red") %>% #use new column
add_axis("y", orient = "left", title = "Weight (lb/1000)" ,title_offset = 50) %>% #fix left axis label
scale_numeric("y", domain = c(0, 0.006), nice = FALSE) %>% #align the ticks as good as possible
add_axis("y", 'ympg' , orient = "right", title= "Miles/(US) gallon" , grid=F ) %>% #remove right y axis grid and name axis
layer_lines( prop('y' , ~mpg, scale='ympg') ) %>% #use scale to show layer_lines which axis it should use
add_axis("x", title = "Displacement (cu.in.)" )
and I think this is what you want:
EDIT:
If you just wanted to plot wt on the left y axis (it is not very clear) then do mutate(wt_scaled=wt/1)
(or remove mutate) and change domain to domain = c(1.5, 5.5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With