2015-10-20 20 views
10

我想将我的图例作为answered in this question插入图中,但对于交互式图。交互式ggvis图上的叠加图例

在第一个代码块中,图例从图上消失,但是当我删除它的交互作用时。

library(ggvis) 
library(dplyr) 

# With drop down list it doesn't work 
mtcars %>% 
    ggvis(x = ~wt, y = input_select(c("Miles per gallon" = "mpg", "Horse power" = "hp", "Displacement"="disp", "Carbohydrates" = "carb"), map = as.name, selected = "mpg", label = "Variables"), fill=~cyl) %>% 
    layer_points() %>% 
    add_relative_scales() %>% 
    add_legend("fill", title = "Cylinders", 
      properties = legend_props(
       legend = list(
       x = scaled_value("x_rel", 0.8), 
       y = scaled_value("y_rel", 1) 
       ))) 

enter image description here

# Remove interaction and it works 
mtcars %>% 
    ggvis(x = ~wt, y = ~mpg, fill = ~cyl) %>% 
    layer_points() %>% 
    add_relative_scales() %>% 
    add_legend("fill", title = "Cylinders", 
      properties = legend_props(
       legend = list(
       x = scaled_value("x_rel", 0.8), 
       y = scaled_value("y_rel", 1) 
       ))) 

enter image description here

我如何可以覆盖传说中的互动情节?

+1

随着你的第一个代码块,当我选择'马力'时,传奇出现了。但是当我选择“每加仑英里数”时,它就消失了。由于y轴的值根据用户的选择而变化,我不知道这个y-lim变化是否有什么关系。我以某种方式认为图例位置设置了最大的y值。 “马力”超过300,而“每加仑英里数”只有34。因此,当选择后者时,传奇消失......这只是我的猜测。 – jazzurro

+0

@jazzurro有趣!谢谢你的猜测。虽然,它似乎是任意的其他选择。我在下拉菜单中增加了两个选项,如果选择'Horse power',然后选择'Displacement',然后选择'Miles每加仑',就会出现。 – Tom

+0

这对我来说似乎很有趣。我想知道这个问题是否在github上提交。这可能值得报道这个案例。 – jazzurro

回答

2

看来这是一个公开的问题。简短的解决办法,我就发现https://github.com/rstudio/ggvis/issues/347:添加

%>% set_options(duration=0) 

的情节的结尾:

))) %>% set_options(duration=0) 

它不重绘传说和因此不会消失。