[英]ggvis density plot with tooltip?
我正在嘗試為我的ggvis圖添加tooltip
。 當我將鼠標懸停在密度圖上時,我基本上想要添加密度值。 這就是我現在所擁有的:
mtcars %>% ggvis(~wt, fill := "red") %>%
layer_densities() %>%
add_axis("x", title = "Weight") %>%
scale_numeric("x", domain = c(0, 5), nice = FALSE, clamp = TRUE) %>%
add_tooltip(function(df){density(df$wt)})
但是當我懸停時,我收到此錯誤:
Error in density.default(df$wt) : argument 'x' must be numeric
謝謝!
我只有部分答案,但它可能會幫助你朝着正確的方向前進。
以下代碼將為您提供工具提示:
mtcars %>% ggvis(~wt, fill:="red") %>%
layer_densities() %>%
add_axis("x", title = "Weight") %>%
add_tooltip(function(data){data$resp_}, "hover")
但是,工具提示包含每個x值的相同值(即:密度曲線的第一個值)。
使用dens <- mtcars %>% compute_density(~wt)
您將獲得密度數據幀。
希望其他人想要改進這個答案,以獲得完整的解決方案..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.