`ggplotly` error on plot with `geom_contour` when one level of a factor isn't represented
未关闭
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
Hi R Plotly Devs,
I hope this finds you well!
This issue involves a dataset with a factor where one factor level isn't represented.
When rendering a ggplot that plots a contour, ggplot will provide informative warnings that zero contours were drawn due to the missing factor level.
However, when this plot object is passed into ggplotly the following error is thrown:
Warning: stat_contour(): Zero contours were generated
Warning in min(x) : no non-missing arguments to min; returning Inf
Warning in max(x) : no non-missing arguments to max; returning -Inf
Error in `$<-.data.frame`(`*tmp*`, "fill", value = NA) :
replacement has 1 row, data has 0
I hope this is a relatively easy fix!
df <- tibble::tribble(
~response, ~variable, ~prediction,
7.45549, 6.24703, "No",
7.45549, 6.62491208333333, "No",
7.45549, 7.00279416666667, "No",
7.45549, 7.38067625, "No",
7.45549, 7.75855833333333, "No",
7.45549, 8.13644041666667, "No"
) |>
dplyr::mutate(prediction = factor(prediction, levels = c("Yes", "No")))
p = ggplot2::ggplot(data = df) +
ggplot2::geom_point(data = df,
ggplot2::aes(
x = .data$response,
y = .data$variable,
color = prediction),
shape = 15,
size = 0.7,
alpha = 0.4) +
ggplot2::geom_contour(data = df,
ggplot2::aes(x = .data$response,
y = .data$variable,
z = as.integer(prediction)),
color = "violet",
size = 0.5,
bins = 1)
plotly::ggplotly(p)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行 issue 中可复现的 R 示例,并跟踪 ggplotly 如何处理由缺失因子水平生成的 zero-contour 图层。完成的标准是:绘图不再抛出数据框替换错误,同时保留信息丰富的 zero-contour 警告。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100