0

I've been trying to do this 3d map but I cant manage. I get all sorts of errors.

# Load required packages
library(rayshader)
library(rgl)
library(sf)

# Load the shapefile
europe <- st_read("C:/data/NUTS_RG_01M_2021_3035.shp")

# Subset the shapefile to only the country level
europe <- europe[europe$LEVL_CODE == 0, ]

# Define the colors for the highlighted countries and the background
highlighted_colors <- c("#64B88B", "#72C095", "#80CB9F", "#8ED4A9", "#9CDCB3", "#AADDAD", "#B8E6B7", "#C6EFC1", "#D4F8CB")
background_color <- "#F5F5F5"
  
# Define the countries to be highlighted
highlighted_countries <- c("IE", "DE", "IT", "BG", "CZ", "MT", "PT", "NL", "UK")

# Assign the colors to each country
europe$color <- ifelse(europe$NUTS_ID %in% highlighted_countries, highlighted_colors, "white")

# Create the plot using rayshader
plot_map(europe, 
         basecolor = background_color,
         raytrace = TRUE,
         windowsize = c(1200, 800),
         zoom = 0.8,
         shadowdepth = -1,
         shadowcolor = "gray50",
         shadowtypes = "raytrace",
         ambient_light = 0.3,
         diffuse_light = 0.7,
         specular_light = 0.1,
         material = "shiny",
         theta = 30,
         phi = 30,
         bg = "white")

# Add the 3D polygons for the highlighted countries
for(i in 1:length(highlighted_countries)){
  highlighted_polygons <- europe[europe$NUTS_ID == highlighted_countries[i],]
  add_polygon_3d(highlighted_polygons, 
                 fill = highlighted_colors[i], 
                 smooth = FALSE, 
                 depth = 0.1,
                 alpha = 1)
}

# Render the plot
render_snapshot("europe_3d.png")

This is one of the errors: Error in if (!(rotate %in% c(0, 90, 180, 270))) { : the condition has length > 1

And sometimes I get this one: Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'plotRGB': unused arguments (basecolor = "#F5F5F5", raytrace = TRUE, windowsize = c(1200, 800), zoom = 0.8, shadowdepth = -1, shadowcolor = "gray50", shadowtypes = "raytrace", ambient_light = 0.3, diffuse_light = 0.7, specular_light = 0.1, material = "shiny", theta = 30, phi = 30, bg = "white")

Any suggestions or a better way to do this?

Thank you!

MVAC
  • 118
  • 8

0 Answers0