ggvis:混淆父层的属性继承

时间:2015-09-09 08:26:08

标签: r shiny ggvis

我的数据框如下:

   x1  x2 y1 y2 labels       colors
1 1.0 1.1  1  2      A   blueviolet
2 1.3 1.4  1  2      A       azure1
3 1.0 1.1  3  4      B navajowhite3
4 1.3 1.4  3  4      B       grey46

包含矩形和标签的位置。但是当我尝试添加文本层时,我收到一条错误消息,即x2和y2是未知属性:

ggvis(data = df2, x = ~x1, y = ~y1, x2 = ~x2, y2 = ~y2) %>% 
   layer_rects(fill = ~colors) %>% 
   layer_text(x = ~ x1 - 1, y = ~y1 + 0.4, text := ~labels)

Error: Unknown properties: x2, y2.
Did you mean: x, y?

如何告诉ggvis删除文本图层的x2和y2?

我已经尝试了以下内容,因为'继承'听起来很有希望:

ggvis(data = df2, x = ~x1, y = ~y1, x2 = ~x2, y2 = ~y2) %>% 
   layer_rects(fill = ~colors) %>% 
   layer_text(props(x = ~ x1 - 1, y = ~y1 + 0.4, inherit = FALSE), 
              text := ~labels)

但是失败并出现以下错误:

Error in new_prop.default(x, property, scale, offset, mult, env, event,  : 
  Unknown input to prop: list(property = "x", value = x1 - 1, scale = "x", offset = NULL, mult = NULL, event = "update", env = <environment>)list(property = "y", value = y1 + 0.4, scale = "y", offset = NULL, mult = NULL, event = "update", env = <environment>)

一种解决方法是再次指定所有图层中的所有属性,但我希望有更好的解决方案:)

1 个答案:

答案 0 :(得分:1)

您的猜测是正确的:您应该使用session_start(); if(isset($_REQUEST['submit'])) : $_SESSION['sessionvalue'] = $_REQUEST['username']; endif; echo $_SESSION['sessionvalue']; ,但不需要将其包含在inherit = FALSE来电中。

props()

enter image description here

从文体的角度来看,您应该在ggvis(data = df2, x = ~x1, y = ~y1, x2 = ~x2, y2 = ~y2) %>% layer_rects(fill = ~colors) %>% layer_text(text := ~labels, inherit = F, x = ~x1 + 0.05, y = ~y1 + 0.5, fontSize := 40) 中仅声明“通用”映射,同时在ggvis内保留特定于图层的映射。在这种情况下,不需要的继承不会成为问题:

layer_*