ggvis add_legend用于'strokeDash'或'strokeWidth'

时间:2016-04-11 08:50:23

标签: r legend ggvis

我想将两个变量的数据分组,并通过'stroke'和'strokeDash'在ggvis图中区分它们。如果我想在ggvis图中添加图例,我可以为'stroke'属性添加:

library(ggvis)

mtcars %>% 
  ggvis(~wt, ~mpg, stroke = ~factor(cyl), strokeDash = ~factor(vs)) %>%
  layer_lines() %>%
  add_legend('stroke', title = 'Number of cylinders')

但是,如果尝试为'strokeDash'添加图例,则不会渲染图:

mtcars %>% 
  ggvis(~wt, ~mpg, stroke = ~factor(cyl), strokeDash = ~factor(vs)) %>%
  layer_lines() %>%
  add_legend('stroke', title = 'Number of cylinders') %>%
  add_legend('strokeDash', title = 'V/S')

同样适用,如果我使用'strokeWidth'代替'strokeDash':

# works
mtcars %>% 
  ggvis(~wt, ~mpg, stroke = ~factor(cyl), strokeWidth = ~factor(vs)) %>%
  layer_lines() %>%
  scale_nominal('strokeWidth', range = c(1,5)) %>% 
  add_legend('stroke', title = 'Number of cylinders')

# does not work
mtcars %>% 
  ggvis(~wt, ~mpg, stroke = ~factor(cyl), strokeWidth = ~factor(vs)) %>%
  layer_lines() %>%
  scale_nominal('strokeWidth', range = c(1,5)) %>% 
  add_legend('stroke', title = 'Number of cylinders')%>%
  add_legend('strokeWidth', title = 'V/S')

有谁知道,为什么“中风”有效,而有些则没有?任何解决方案?

谢谢, 费边

0 个答案:

没有答案