如何在ggvis中添加一条水平线?
How can I add a horizontal line in ggvis?
我正在尝试学习 ggvis,并且我正在 Boston 作为教程工作。基本上,我正在尝试将我处理的 ggplot 转换为 R 中波士顿数据的 ggvis。似乎我无法在 ggvis 中添加水平平均线。虽然我在谷歌搜索后发现了一些 hack,但我仍然无法弄清楚如何在我的代码中解决它。这是我的代码:
library(dplyr, warn.conflicts = FALSE)
library(ggvis)
Boston %>%
ggvis(~chas, ~log(medv), fill=~chas, opacity := 0.8) %>%
layer_boxplots(size := 10)
所以,这就是情节,我想添加平均线。这是我试过的:
data_line = data.frame(
x_rng = c(0,1), #this is the part that I couldn't figure out.
y_rng = c(3,3)
)
layer_lines(~x_rng, ~y_rng, data=data_line) #this is what I added to the code above.
这没有产生我想要的结果。事实上,它给了我一个错误。
## Error in new_prop.default(x, property, scale, offset, mult, env, event, :
## Unknown input to prop: c(0, 1)c(3, 3)
你不能只用 dplyr 在波士顿数据框中添加一个新的平均值列吗?
mutate(boston, line=mean("what you want the mean of")
然后添加%>% layer_paths(~x,~meanvalue,stroke:=black)
我正在尝试学习 ggvis,并且我正在 Boston 作为教程工作。基本上,我正在尝试将我处理的 ggplot 转换为 R 中波士顿数据的 ggvis。似乎我无法在 ggvis 中添加水平平均线。虽然我在谷歌搜索后发现了一些 hack,但我仍然无法弄清楚如何在我的代码中解决它。这是我的代码:
library(dplyr, warn.conflicts = FALSE)
library(ggvis)
Boston %>%
ggvis(~chas, ~log(medv), fill=~chas, opacity := 0.8) %>%
layer_boxplots(size := 10)
所以,这就是情节,我想添加平均线。这是我试过的:
data_line = data.frame(
x_rng = c(0,1), #this is the part that I couldn't figure out.
y_rng = c(3,3)
)
layer_lines(~x_rng, ~y_rng, data=data_line) #this is what I added to the code above.
这没有产生我想要的结果。事实上,它给了我一个错误。
## Error in new_prop.default(x, property, scale, offset, mult, env, event, :
## Unknown input to prop: c(0, 1)c(3, 3)
你不能只用 dplyr 在波士顿数据框中添加一个新的平均值列吗?
mutate(boston, line=mean("what you want the mean of")
然后添加%>% layer_paths(~x,~meanvalue,stroke:=black)