Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

Using geom_sf in R, is there a way to create a 3d map?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with grok-3-mini-high’s answer.
  1. User

    Using geom_sf in R, is there a way to create a 3d map?

  2. Claude Assistant

    No, geom_sf in ggplot2 is designed specifically for 2D mapping and doesn't support 3D visualization. It's built around the grammar of graphics framework which operates in 2D space.

    For 3D mapping in R, you'll want to use different packages:

    For interactive 3D maps:

    • leaflet with elevation data can create pseudo-3D effects
    • mapview offers some 3D capabilities
    • plotly can convert some ggplot objects to interactive 3D, though this works better with regular geom layers than sf objects

    For true 3D spatial visualization:

    • rgl package for 3D plotting with spatial data
    • rayshader is excellent for creating 3D terrain maps and can even render ggplot2 maps in 3D
    • threejs for web-based 3D visualizations

    Example approach with rayshader:

    library(rayshader)
    library(ggplot2)
    
    # Create your 2D ggplot with geom_sf
    p <- ggplot(your_sf_data) + geom_sf()
    
    # Convert to 3D
    plot_gg(p, width = 5, height = 5, scale = 250)
    

    If you need to stick with the sf ecosystem, you could extract coordinates from your sf objects and use them with 3D plotting packages, but you'd lose the convenient spatial plotting features that geom_sf provides.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.