Once the scene looks good, it's time to set up the final render.Ī word of caution, this used an immense amount of RAM, so make sure you have SWAP setup if you're using Linux. So we'll leave those at the default to make sure the lighting for the scene looks good. Rendering time seems to scale primarily with the number of samples, the min_deviation, and the number of pixels out. Once you've dialed in the camera and zscale settings, it's time to dial in the render settings. Other scenes will definitely need different values here. theta is the rotation angle in degrees (imagine looking down at a compass), phi is the azimuth angle, and zoom controls how much the camera is zoomed into the scene. The plot_3d function has a ton of features to experiment with, these are just the ones I landed on.Īfter zscale, the render_camera() function specifies where the camera is placed in the scene. Rgl::rglwidget() # Required to show the window in an RStudio NotebookĪ lower zscale value exaggerates elevation features, or in other words, lower values make the plot look hillier, and higher values make the plot look flatter. Render_camera(theta = -15, phi = 50, zoom =. The size parameter will dramatically affect RAM usage and runtime, so I recommend starting with a smaller number (500-1000) while setting up your render. To create this 2D matrix, we'll need to rasterize the population hexagons so we can generate the matrix. Rayshader works by taking in a 2D Matrix where each value corresponds to the height it should render. Looks good! Building a 2D Heightmap Matrix We should do a quick check before moving forward to make sure it looks like we got it right: df_dmv_st |> Library(tidyverse) # need this for filter and ggplot later, but couldįilter(name %in% c("District of Columbia", "Virginia", "Maryland")) |>įilter(statefp %in% statefps$statefp, namelsad %in% counties_list) |>įilter(statefp != '51' | namelsad != 'Montgomery County') |> # exclude Montgomery County, Virginia Even in the DMV, there's a Montgomery County in both Maryland and Virginia, which will require an extra filter too. The counties shapefile doesn't include a state names, so you'll need to get the StateFP codes before filtering on county name, since many states have overlapping county names. The tigris package makes it easy to download county and state shapefiles and load them into R. I spent a bit of time googling what the official definition of the DC Metropolitan area is, but in the end I decided to limit it to the counties and cities that Metrorail runs through. To focus in on the DC metropolitan area, we'll need to filter for DC and the counties around it. # install.packages("sf")ĭf_pop_st <- st_read(gunzip(destination_file, remove=FALSE, skip=TRUE))Ĭolnames(df_pop_st) <- tolower(colnames(df_pop_st)) # this is just personal preference The file is compressed using gzip, so we'll need to unzip the file before we can extract the data we want. You could navigate to the website and hit download, or you can download the data directly using R: url <- ''ĭestination_file <- 'kontur_population_US_'ĭownload.file(url, destination_file, 'curl') Data is available by country, for this we'll download data for the U.S. Kontur.io is kind enough to provide population density data. Remotes::install_github("") Making the Mapįirst we'll need to download the data. This meant the flow for installing my R packages was something like install.packages("tidyverse") The other R packages depend on a lot of open source tools for geospatial analysis, all of which need to be installed at both the OS level and in R. I started off by installing R and Rstudio, which was easy thankfully: sudo dnf install -y R rstudio-desktop I'm using Fedora these days and sadly getting everything setup was a bit of a hassle. You can find Spencer's git repo with the code from the video on Github, and the video tutorial below: The Setup I wanted to try my hand at making it myself, and I thought it would be nice to have instructions in written form if anyone is interested. While 3D map datavizzes like these can be more of a flashy piece of art than a helpful graphic if you're not careful, I still immediately wanted to know how to make one of these maps myself.īefore jumping in here, I want to give full credit to Spencer Schien for the live-coding tutorial that I based this post on. The reason I saw the post though was that someone was pointing out how many of Canada's dense cities are in a straight line and would be perfect for high-speed rail.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |