資料:https ://github.com/yuliaUU/data/blob/main/test.csv
griddf <- read_csv("test.csv")
創建地圖:
world <- rnaturalearth::ne_countries(scale = "medium", returnclass = "sf") # add continents
ggplot()
geom_tile(data = Data |> dplyr::filter(Model.1=="RF"), aes(x = Lon, y = Lat, fill= value/1000)) geom_sf(data=world)
viridis:: scale_fill_viridis(option = "H", na.value = NA)
labs(fill="Probability")
facet_wrap(~ Model.1)
我的問題是它創建了一個帶有“線條”的地圖,我不明白為什么。我知道這與我正在使用的不規則網格有關(所有網格單元應該是相等的面積)

當我添加不同的投影時:
coord_sf(crs = ' proj=moll')
我什么也沒畫

uj5u.com熱心網友回復:
你基本上自己回答了這個問題——你的資料太細了。要獲得更“完整”的外觀,您可能需要對值進行 2d 插值。在這里,我正在使用akima::interp,但還有其他功能 - 這里不是討論哪個最好用的地方。
library(ggplot2)
griddf <- read.csv(url("https://raw.githubusercontent.com/yuliaUU/data/main/test.csv"))
world <- rnaturalearth::ne_countries(scale = "medium", returnclass = "sf") # add continents
val_interpol <- with(griddf, akima::interp(Lon, Lat, value, xo = -180:180, yo = -90:90))
#> Warning in akima::interp(Lon, Lat, value, xo = -180:180, yo = -90:90): collinear
#> points, trying to add some jitter to avoid colinearities!
#> Warning in akima::interp(Lon, Lat, value, xo = -180:180, yo = -90:90): success:
#> collinearities reduced through jitter
## thanks Akrun https://stackoverflow.com/q/58123551/7941188
## matrix doesn't allow negative values for subsetting
d1 <- expand.grid(x = 1:361, y = 1:181)
out <- transform(d1, z = val_interpol$z[as.matrix(d1)])
out$x <- out$x-181
out$y <- out$y-91
ggplot()
geom_raster(data = out , aes(x = x, y = y, fill= z), interpolate = TRUE)
geom_sf(data=world)
labs(title=paste0("Swordfish Probability of Occurance"),
x="", y="", subtitle="data from 2000-present (0.5x0.5 grid)")
viridis:: scale_fill_viridis(option = "H", na.value = "black")

由reprex 包創建于 2022-05-06 (v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/471586.html
