我最終試圖繪制不規則資料集的等高線圖或“光柵圖”——當然這是一個相當普遍的問題。許多解決方案建議首先插入資料,然后繪制它,例如這里:
我現在想用輪廓來達到同樣的效果。我天真地嘗試過
StatInterpContour <- ggproto("StatInterpContour", Stat,
compute_group = function(data, scales) {
ii<-akima::interp(x = data$x,
y = data$y,
z = data$z)
data.out <- tibble(x = rep(ii$x, nrow(ii$z)),
y = rep(ii$y, each = ncol(ii$z)),
z = as.numeric(ii$z) )
#StatContour(data.out)
return(data.out)
},
required_aes = c("x", "y", "z")
)
stat_interp_contour<- function(mapping = NULL, data = NULL, geom = "contour",
position = "identity", na.rm = FALSE, show.legend = NA,
inherit.aes = TRUE, ...) {
layer(
stat = StatInterpContour, data = data, mapping = mapping, geom = geom,
position = position, show.legend = show.legend, inherit.aes = inherit.aes,
params = list(na.rm = na.rm, ...)
)
}
這與上面的基本相同。但是它不會產生預期的結果:
ee %>% ggplot() geom_contour(aes(x=x,y=y,z=z),stat=StatInterpContour)

回想起來,這并不奇怪。我的統計資料正在生成一個常規資料陣列,在 x 和 y 中具有整齊有序的值,但我沒有生成實際的行。等高線更復雜,似乎是由 xyz_to_isolinesstat_contour 生成的(參見
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/482744.html
