Controlling Animation for Points When There Are Missing Values (ggplotly)
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
I am building a Hans Rosling type visualisation, however, I am having issues with the point movements. I have attached some code that creates an example of my problem, which can be found below.
The best way I can describe it is that whenever there is a missing value, a point has to disappear, therefore a different becomes assigned to a point even if it's in a different group. This logically doesn't make any sense to me.
In the example below, I've removed the Month Year of Feb 2021 from Clinic A, (i.e. I've removed the whole row), which means that the point disappears as shown in the play animation movement. However, if you notice instead of the Clinic A point simply disappearing, it chooses to keep the Clinic A point, turn into a different Clinic, in this case Clinic B and also convert the surrounding points to different clinics as well. I think it's working off the logic of turn into whatever point is the nearest somehow.
To really understand what is happening observe the hover of the points from Jan 2021 to Feb 2021
My question(s) is/are:
- Why is this happening?
- How do I specify some sort of group or ID to the points so that they aren't randomly turning into other Clinics?
In my real world scenario I have over 90+ different unique IDs/Clinics so ideally someone would be able to press play and then follow a single point moving across the viz, specifically noticing for any abnormalities in movement. It's extremely difficult to do this, or rather almost impossible, if a given point is converting itself into another point on the fly.
Note: I have confirmed this problem is replicated when using both plot_ly() and ggplotly() and only seems to happen when there is missing data
Code to Replicate Problem:
set.seed(24)
test <- data.frame(Month_Year = rep(paste(month.abb, rep(2021:2022, each = 12), sep = "_"), 4),
x = abs(rnorm(24*4)),
y = abs(rgamma(24&4,2,1)),
Clinic = rep(c("Clinic A", "Clinic B", "Clinic C", "Clinic D"), each = 24))
test$Month_Year <- factor(test$Month_Year, levels = paste(month.abb, rep(2021:2022, each = 12), sep = "_"))
test <- test[-c(2,8,12),]
pt <- test %>%
ggplot(aes(x = x, y = y, frame = paste0(sprintf("%02d", as.numeric(Month_Year)), Month_Year), text =
paste(
"RAR:", round(y, 3),
"\nMR:", round(x, 3),
"\nClinic:", Clinic
))) +
geom_point(shape = 1, color = "firebrick", aes(group = Clinic)) +
# geom_text(aes(y = NAG + 5)) +
theme_minimal() +
labs(x = "Rolled Mortality Rate - 3 Month Average", y = "Rolled Admission Rate - 3 Month Average") +
scale_x_continuous(limits = c(0, 6))
ggplotly(pt, tooltip = "text") %>%
animation_opts(
3000,
redraw = T
) %>%
animation_slider(
currentvalue = list(prefix = "Month Year: ")
)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行提供的 R 复现,分别使用 plot_ly() 和 ggplotly(),并包含 animation_opts() 和 animation_slider()。在存在缺失行时,比较 Jan 2021 和 Feb 2021 之间的点身份和悬停标签。完成的标准是解释清楚该行为,并确定一种有文档记录的保留 Clinic 身份的方法,或确定一个范围明确的修复方案。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100