2014-12-20 8 views
13

यह वही मैं आरएक माध्यमिक y अक्ष बनाएं लाइनों का ग्राफ़ बनाने के लिए ggvis आर

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

में ggvis पैकेज के साथ अब तक किया है साथ मैं चला Y अक्ष wt पैमाने डेटा का प्रतिनिधित्व करने के लिए नहीं मिल सकता है।

यह आउटपुट:

enter image description here

उत्तर

12

मैं आप 1000 से विभाजित बाईं y अक्ष (यानी wt) चाहते मान:

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

और मुझे लगता है कि यह तुम क्या चाहते है:

enter image description here

संपादित:

अगर तुम सिर्फ बाईं y अक्ष पर भार साजिश करना चाहता था (यह बहुत स्पष्ट नहीं है) तो mutate(wt_scaled=wt/1) कर (या मे बदलें निकालने के लिए) और परिवर्तन डोमेन domain = c(1.5, 5.5)

को
संबंधित मुद्दे