style(hoveron="fills") doesn't work with ggplotly() when there are multiple polygons with the same fill color
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
The following code based on the standard North Carolina shape-file fills counties by the values of BIR74, except that one county has been given an NA value for the variable.
library(ggplot2)
library(plotly)
library(sf)
nc_1 <-
st_read(system.file("shape/nc.shp", package = "sf"),
quiet = TRUE) %>%
mutate(BIR74 = ifelse(NAME == "Ashe", NA, BIR74)) %>%
mutate(tooltip_text = ifelse(is.na(BIR74),
paste0(NAME, " not reporting"),
paste0(NAME, " reports ", BIR74)))
p_1 <-
nc_1 %>%
ggplot() +
geom_sf(aes(fill = BIR74, text = tooltip_text))
ggplotly(p_1, tooltip = "text") %>%
style(hoveron = "fills")
The custom tooltip indicates the missing value (hover over Ashe County) as expected.
The following code sets BIR74 to NA for two counties:
nc_2 <-
st_read(system.file("shape/nc.shp", package = "sf"),
quiet = TRUE) %>%
mutate(BIR74 = ifelse(NAME %in% c("Ashe", "Alleghany"), NA, BIR74)) %>%
mutate(tooltip_text = ifelse(is.na(BIR74),
paste0(NAME, " not reporting"),
paste0(NAME, " reports ", BIR74)))
p_2 <-
nc_2 %>%
ggplot() +
geom_sf(aes(fill = BIR74, text = tooltip_text))
ggplotly(p_2, tooltip = "text") %>%
style(hoveron = "fills")
Hover over either Ashe or Alleghany and you get identical very long tooltips.
The output of plotly_json(p_2) indicates that Ashe and Alleghany have somehow been combined. See, e.g.:
json_2 <- plotly_json(p_2)
json_2$x$data %>%
as.character() %>%
RJSONIO::fromJSON() %>%
.$data %>%
.[[100]] %>%
.[1:3]
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用 ggplotly()、tooltip = "text" 和 style(hoveron = "fills") 运行两个 North Carolina 示例,然后按照所示检查 plotly_json(p_2)。比较一个 NA 和两个 NA 的情况如何表示多边形数据;完成标准是 Ashe 和 Alleghany 各自显示自己的 tooltip,而不是一个合并的长 tooltip。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100