使用ggvis
包在R中绘制以下内容,
代码是
mtcars %>%
ggvis(~wt, ~mpg, fill = ~factor(cyl)) %>%
layer_points() %>%
group_by(cyl) %>%
layer_model_predictions(model = "lm")
如果我在上面将fill
更改为shape
,则会出现错误:
Error: Unknown properties: shape.
Did you mean: stroke?
为什么呢?如何达到预期的效果?
答案 0 :(得分:6)
您必须在shape
电话中指定layer_points()
:
mtcars %>%
transform(cyl = factor(cyl)) %>%
ggvis(~wt, ~mpg) %>%
layer_points(shape = ~cyl, fill = ~cyl) %>%
group_by(cyl) %>%
layer_model_predictions(model = "lm", formula=mpg~wt)
(请注意,我使用transform()
将cyl
转换为系数。这意味着您无需将cyl
转换为ggvis()
调用中的因子,情节键有点整洁。)