0

我有一个ggplot2::geom_tile()需要几十秒才能渲染的情节,所以我根本不想让它重新渲染,但我确实想注册点击事件(用于shiny::nearPoints选择在其他一些情节中显示的内容)并且理想情况下我想在点击的位置出现注释。是否可以添加某种叠加层以显示单击的位置?

4

1 回答 1

0

我最终制定了一个解决方案,我用它ggplot2::layer_grob()来计算一次栅格,保存它,然后annotation_raster在需要更新后者时将其添加到绘图中,并在顶部添加其他注释:


temp = ggplot(dat)+geom_raster(aes(x=x,y=y,fill=value))
raster = layer_grob(temp)$`1`$raster
p = (
    ggplot(dat)
    + annotation_raster(
        raster = raster
        , xmin = min(dat$x)
        , xmax = max(dat$x)
        , ymin = min(dat$y)
        , ymax = max(dat$y)
    )
)

#now p will re-render nearly instantly and you can add other geoms/annotations on top

于 2020-11-23T14:55:57.493 回答