library(tidyverse)
library(sf)
library(tigris)
library(rayshader)
library(PrettyCols)
library(stars)
Overview
Map of Oregon Population Density
. Data is from Kontur population US
and the {tigris}
package.
Inspiration:
<- "https://geodata-eu-central-1-kontur-public.s3.amazonaws.com/kontur_datasets/kontur_population_US_20220630.gpkg.gz"
url # downloader::download(url, dest="data/kontour_pop_cr.zip", mode="wb")
<- st_read("data/kontur_population_US_20220630.gpkg")
data # save(data,file="data/data.RData")
<- tigris::states() |>
s st_transform(crs = st_crs(data))
# save(s,file="data/s.RData")
%>%count(NAME) s
<- s |>
or filter(NAME == "Oregon")
<- st_intersection(data, or)
or_d # save(or_d,file="data/or_d.RData")
load("data/or_d.RData")
<- st_bbox(or_d)
bb <- st_distance(st_point(c(bb[["xmin"]], bb[["ymin"]])),
yind st_point(c(bb[["xmin"]], bb[["ymax"]])))
<- st_distance(st_point(c(bb[["xmin"]], bb[["ymin"]])),
xind st_point(c(bb[["xmax"]], bb[["ymin"]])))
/ yind
xind
<- 2500
size <- st_rasterize(or_d |>
rast select(population, geom),
nx = floor(size * (xind/yind)), ny = size)
# save(rast,file="data/rast.RData")
load("data/rast.RData")
<- matrix(rast$population,
mat nrow = floor(size * (xind/yind)),
ncol = size)
<- "pink_greens"
pal
<- prettycols("TangerineBlues")
c1 <- c(c1[c(6:8, 2:4)])
colors # swatchplot(colors)
::scico_palette_show()
scico<- scico::scico(6,palette="bamako")
colors
<- grDevices::colorRampPalette(colors, bias = 2)(256)
texture # swatchplot(texture)
::rgl.close() rgl
|>
mat height_shade(texture = texture) |>
plot_3d(heightmap = mat,
solid = FALSE,
soliddepth = 0,
z = 20,
shadowdepth = 0,
windowsize = c(800,800),
phi = 90,
zoom = 1,
theta = 0,
background = "white")
::render_camera(phi = 50,
rayshaderzoom = .85,
theta = 45)
render_snapshot(title_text = "#30DayMapChallenge Day 28:3D | Graphics: @fgazzelloni\n\nOregon Population density, US",
title_color = "navy",
title_font = "Comic Sans",
title_size = 25,
title_bar_alpha = 0.5,
title_bar_color = "#a5a7c4",
vignette = 0.2,
filename = "day28_3D2.png")