ggvis - 使用变量赋值 "x" 属性 使用 props
ggvis - using a variable to assign "x" property using props
根据 properties and scales reference and this 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()
任何人都可以告诉我我做错了什么吗?
我找到了 prop()
的正确用法,它不属于 %>%
链,它是 ggvis
或 layer_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()
根据 properties and scales reference and this 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()
任何人都可以告诉我我做错了什么吗?
我找到了 prop()
的正确用法,它不属于 %>%
链,它是 ggvis
或 layer_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()