【发布时间】:2015-09-09 08:26:07
【问题描述】:
我有这样的数据框:
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>)
一种解决方法是再次指定所有层中的所有属性,但我希望有更好的解决方案:)
【问题讨论】: