在想要添加工具提示时,我无法让layer_points()
和layer_boxplot()
一起工作。
require(ggvis)
### Example Data
mtc<-mtcars
mtc$label <- rownames(mtcars) #unique Identifier
## Tooltip but not boxplot - works fine
mtc %>%
ggvis(~cyl, ~qsec, key:= ~label) %>%
layer_points(size := 15) %>%
set_options(width = "auto") %>%
add_tooltip(function(data) data$label)
})
## No tooltip - boxplot + points - works fine
mtc %>%
ggvis(~cyl, ~qsec) %>%
layer_points(size := 15) %>%
layer_boxplots(size := 0) %>%
set_options(width = "auto")
## Attempt at combining boxplot, points, tooltip - fails
mtc %>%
ggvis(~cyl, ~qsec, key:= ~label) %>%
layer_points(size := 15) %>%
layer_boxplots(size := 0) %>%
set_options(width = "auto") %>%
add_tooltip(function(data) data$label)
#Error in eval(expr, envir, enclos) : object 'label' not found
#Plot is produced but no interactivity
有没有人知道如何将箱形图重叠到layer_points()
加上工具提示(基本上是为了识别异常值是我的目标)。
另一个答案是如何为从layers_boxplot()
答案 0 :(得分:1)
好像我已经解决了 - 他们key
必须进入layer_points()
mtc %>%
ggvis(~cyl, ~qsec) %>%
layer_points(key:= ~label, size := 15) %>%
layer_boxplots(size := 0) %>%
set_options(width = "auto") %>%
add_tooltip(function(data) data$label)