该内容已被发布者删除 该内容被自由微信恢复。
文章于 3月30日 下午 8:30 被检测为删除。
被用户删除
其他
R语言绘图 | 使用Tanaka绘制优美的三维地图
介绍
加载R包
install.packages("tanaka")
绘图
library(tanaka)
library(terra)
ras <- rast(system.file("tif/elev.tif", package = "tanaka"))
tanaka(ras, breaks = seq(80,400,20),
legend.pos = "topright", legend.title = "Elevation\n(meters)")
library(tanaka)
library(elevatr)
library(terra)
# use elevatr to get elevation data
ras <- get_elev_raster(locations = data.frame(x = c(6.7, 7), y = c(45.8,46)),
z = 10, prj = "EPSG:4326", clip = "locations")
ras <- rast(ras)
# custom color palette
cols <- c("#F7E1C6", "#EED4C1", "#E5C9BE", "#DCBEBA", "#D3B3B6", "#CAA8B3",
"#C19CAF", "#B790AB", "#AC81A7", "#A073A1", "#95639D", "#885497",
"#7C4692", "#6B3D86", "#573775", "#433266", "#2F2C56", "#1B2847")
# display the map
tanaka(ras, breaks = seq(500,4800,250), col = cols)
library(terra)
library(sf)
library(tanaka)
library(mapsf)
# Download
tempzip <- tempfile()
tempfolder <- tempdir()
data_url <- paste0("http://cidportal.jrc.ec.europa.eu/ftp/jrc-opendata/GHSL/",
"GHS_POP_GPW4_GLOBE_R2015A/GHS_POP_GPW42015_GLOBE_R2015A_54009_1k/",
"V1-0/GHS_POP_GPW42015_GLOBE_R2015A_54009_1k_v1_0.zip")
download.file(data_url, tempzip)
unzip(tempzip, exdir = tempfolder)
# Import
pop2015 <- rast(paste0(tempfolder,
"/GHS_POP_GPW42015_GLOBE_R2015A_54009_1k_v1_0/",
"GHS_POP_GPW42015_GLOBE_R2015A_54009_1k_v1_0.tif"))
# Mask raster
center <- st_as_sf(data.frame(x=425483.8, y=5608290),
coords=(c("x","y")),
crs = st_crs(pop2015))
center <- st_buffer(center, dist = 800000)
ras <- crop(pop2015, st_bbox(center)[c(1,3,2,4)])
# Smooth values
mat <- focalMat(x = ras, d = c(10000), type = "Gauss")
rassmooth <- focal(x = ras, w = mat, fun = sum, na.rm = TRUE)
# Map
bks <- c(0,25,50,100,250,500,750,1000,1750,2500,5000, 7500,10000)
mf_export(x = center, filename = "circle.png", width = 800, res = 100)
tanaka(x = rassmooth,
breaks = bks,
mask = center,
col = hcl.colors(n = 12, palette = "Inferno"),
shift = 2500,
add = TRUE,
legend.pos = "topleft",
legend.title = "Inhabitants\nper km2")
mf_map(center, add = TRUE, border = "white", col = NA, lwd = 6)
mf_title(txt = "Smoothed Population Density")
mf_credits(paste0("T. Giraud, 2022\n",
"Data : European Commission, Joint Research Centre (JRC); ",
"Columbia University, CIESIN (2015): GHS population grid, ",
"derived from GPW4."))
text(-250000 ,6420000, "Gaussian filter, sigma = 10km",
adj = 0, font = 3, cex = .8, xpd = TRUE )
dev.off()
「大家有兴趣可以加群,可以在群里讨论,学习,共同进步!」