2017-06-18 72 views
0

基本上我有我的ggvis正在繪製一個數據幀,但我想嘗試顏色的情侶特定點,並添加一個表,以紀念那些什麼點,指。到目前爲止,我可以爲這些點添加顏色,但我無法創建識別該點的圖例。如何在ggvis中添加特定點到圖例?

g1 <- subset(ex, p == 0.10) 

ex %>% ggvis(x = ~p, y = ~Pa_Achieved) %>% layer_lines() %>% 
    layer_points() %>% layer_points(data = g1, fill := "red") %>% 
    add_axis("x", title ="p") %>% 
    add_axis("y", title = "Pa", 
      properties=axis_props(labels=list(fontSize=12), 
           title=list(fontSize=12,dy=-25))) %>% 
    add_title(title = "Operating Characteristic Curve", 
      properties = axis_props(title=list(fontSize=20))) 

基本上我想補充的顏色這種和其他三個點,一個簡單的傳奇確定什麼這些點是其各自的顏色,並留下其他點黑。

+0

請中,添加一個可再現的例子(https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Lstat

回答

0

要從常量而不是變量創建圖例,您將需要= ~而不是:=。您可以控制使用哪些顏色填充scale_nominal,並可以使用add_legend更改圖例的外觀。

下面是使用mtcars一個例子。

mtcars %>% 
    ggvis(x = ~mpg, y = ~wt) %>% 
    layer_points() %>% 
    layer_points(data = subset(mtcars, mpg == 33.9), fill = ~"mpg 33.9") %>% 
    layer_points(data = subset(mtcars, mpg == 32.4), fill = ~"mpg 32.4") %>% 
    scale_nominal("fill", range = c("red", "blue")) %>% 
    add_legend("fill", title = "groups") 

enter image description here

+0

稀釋,這是正是我正在尋找的!非常感謝!! – Imconfused

相關問題