You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ggplot绘图触发libpng错误及图形路径非有限值问题求助

ggplot绘图触发libpng错误及图形路径非有限值问题求助

大家好!我最近在用ggplot处理投球数据的2D密度图时卡壳了,遇到了一堆头疼的错误,已经尝试过过滤NA值和非有限值,但问题依然存在,想请教下各位大佬帮忙排查下原因!

我的代码如下:

BurnesCutterHeat <- colorRampPalette(paletteer::paletteer_d("RColorBrewer::RdBu", n = 9, direction = -1))(16)

BurnesPitches %>% 
  filter(pitch_name == "Cutter" & !is.na(plate_x) & !is.na(plate_z) & is.finite(plate_x) & is.finite(plate_z)) %>%
  ggplot(mapping = aes(x = plate_x, y = plate_z)) +
  stat_density2d_filled() +
  scale_fill_manual(values = c(BurnesCutterHeat), aesthetics = c("fill", "color"))

运行后收到的错误信息如下:

libpng warning: Image height is zero in IHDR
libpng error: Invalid IHDR data
Error in grid.Call.graphics(C_path, x$x, x$y, index, switch(x$rule, winding = 1L,  : 
  non-finite x or y in graphics path
In addition: Warning message:
In grid.newpage() : agg could not write to the given file

一开始看到“non-finite x or y in graphics path”这个错误提示,我立刻就在filter步骤里加上了排除NA、只保留有限值的条件,但再次运行还是触发了相同的错误,实在摸不着头脑了...

备注:内容来源于stack exchange,提问作者Samuel Basso

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.16 07:13:11