【问题标题】:ggvis density plot with tooltip?带有工具提示的ggvis密度图?
【发布时间】:2014-06-30 15:08:37
【问题描述】:

我正在尝试将tooltip 添加到我的 ggvis 图中。当我将鼠标悬停在密度图上时,我基本上想添加密度数。这就是我现在拥有的:

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

谢谢!

【问题讨论】:

    标签: r ggvis


    【解决方案1】:

    我只有部分答案,但它可能会帮助你朝着正确的方向前进。

    以下代码将为您提供工具提示:

    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),您将获得一个密度数据框。

    希望其他人想改进这个答案以获得完整的解决方案..

    【讨论】:

    • 这绝对是出乎意料的行为,也许我们应该把它放在github上的问题队列中。我能想出的唯一解决方案是使用已经计算过的密度值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    • 1970-01-01
    • 2017-03-15
    相关资源
    最近更新 更多