【问题标题】:ggvis - using a variable to assign "x" property using propsggvis - 使用变量使用道具分配“x”属性
【发布时间】:2016-09-23 17:49:40
【问题描述】:

根据properties and scales referencethis SO post,我应该能够使用如下所示的 props(prop()) 调用来创建图表。不过,我遇到了一个难以理解的错误。

test_df <- data.frame(cbind(x_vals = letters[1:5],
                            y_vals = 1:5)) 

图表正确:

test_df %>% ggvis(x = ~x_vals, y = ~y_vals) %>% 
  layer_points() 

有错误:

x_val_variable <- "x_vals"

test_df %>% ggvis(y = ~y_vals) %>% 
      props(prop("x", as.name(x_val_variable)) %>% 
      layer_points()

谁能帮我告诉我我做错了什么?

【问题讨论】:

  • props() 的东西看起来确实令人困惑。我很确定你不能加入%&gt;% 链。它应该在 ggvis()~ or layer_points()` 调用中。我无法让它工作,但我确实让test_df %&gt;% ggvis(x=as.name(x_val_variable), y = ~y_vals) %&gt;% layer_points() 工作。这似乎做你想做的事。
  • 我想通了。你是正确的props() 不属于链。我今天花了 5 个小时在这上面!

标签: r ggvis


【解决方案1】:

我弄清楚了prop()的正确用法,它不属于%&gt;%链,它是ggvislayer_points()的参数。我仍然不明白你什么时候会使用props()

test_df <- data.frame(cbind(x_vals = letters[1:5],
                            y_vals = 1:5)) 

x_val_variable <- "x_vals"

#you can use either one of these, they are identical
p1 <- prop("x", as.name(x_val_variable))
p2 <- prop("x", parse(text = x_val_variable)[[1]])

test_df %>% ggvis(p1, y = ~y_vals) %>% layer_points()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-04
    • 2019-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-14
    相关资源
    最近更新 更多