geom_raster似乎无法在我的计算机上工作,x轴上的值超过2 ' 15 -1.我不明白它为什么这样做.我确信我过go 曾绘制过这样的图表,但我不明白是什么变化(可能在我的电脑上)导致图形现在失败. 请随时提出任何建议并提前感谢.
这是一个在我这一端产生奇怪结果的代码.第一个图形失败(但没有错误),第二个图形按预期工作.
library(ggplot2)
df <- expand.grid(y = 0:4,
x = 1:2^(15))
df$fill <- rnorm(2^15)
# Plot 1, failing (return empty ggplot)
ggplot(df) +
geom_raster(aes(x = x, y = y, fill = fill))
# Plot 2, working as intended
ggplot(df[1:(2^15 - 1),]) +
geom_raster(aes(x = x, y = y, fill = fill))
该代码在我的计算机上进行了测试.下面是sessionInfo()
的输出.我try 过玩R
版本和ggplot2
版本,但没有任何效果.我要求一位同事在他的计算机上测试代码,它运行顺利(两个图都有效),R 4.2.3和4.4.0(但使用Windows系统)也是如此.我可以通过使用geom_tile
来解决这个问题,但我更愿意使用geom_raster
并了解为什么它不再工作.任何建议都将不胜感激.
R version 4.3.3 (2024-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.4 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8 LC_PAPER=en_GB.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
time zone: Europe/Paris
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_3.5.1
loaded via a namespace (and not attached):
[1] labeling_0.4.3 utf8_1.2.4 R6_2.5.1 tidyselect_1.2.1 farver_2.1.1 magrittr_2.0.3
[7] gtable_0.3.5 remotes_2.5.0 glue_1.7.0 tibble_3.2.1 pkgconfig_2.0.3 generics_0.1.3
[13] dplyr_1.1.4 lifecycle_1.0.4 cli_3.6.2 fansi_1.0.6 scales_1.3.0 grid_4.3.3
[19] vctrs_0.6.5 withr_3.0.0 compiler_4.3.3 rstudioapi_0.16.0 tools_4.3.3 pillar_1.9.0
[25] munsell_0.5.1 colorspace_2.1-0 rlang_1.1.3