Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8863517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:59:53+00:00 2026-06-14T15:59:53+00:00

I am playing with a spatial data set (mostly polygons over an area of

  • 0

I am playing with a spatial data set (mostly polygons over an area of a city) and I would like to produce different views, based on different levels of zoom.
Everything is fine when I have the plot boundary box larger than the area that contains the polygons. But on a zoom in, some polygons get parts that are outside the boundary box and the output for those polygons is problematic : the points of the polygon outside the boundary box are not displayed, resulting in polygons that are not cropped at boundary box limits (as would be expected) but rather are not considered. the polygons are incomplete and the polygon only joins the points remaining on the plot (normal behavior, but not wanted).

a good example worth all the discussion, here is a demo of the problem:

#initialisation
library(ggmap)
require(MASS)

data(zips)

# overview
ggmap(get_map(maptype = "satellite", zoom = 8), extent = "device") +
        geom_polygon(aes(x = lon, y = lat, group = plotOrder),
                data = zips, colour = NA, fill = "red", alpha = .5) +
        geom_path(aes(x = lon, y = lat, group = plotOrder),
                data = zips, colour = "white", alpha = .7, size = .4)

# problematic view    
x11()
ggmap(get_map(maptype = "satellite", zoom = 12), extent = "device") +
        geom_polygon(aes(x = lon, y = lat, group = plotOrder),
                data = zips, colour = NA, fill = "red", alpha = .5) +
        geom_path(aes(x = lon, y = lat, group = plotOrder),
                data = zips, colour = "white", alpha = .7, size = .4)

would you know of a nice technique to properly crop the polygons at plot boundary box limits ?
thanks for your help

Pascal

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:59:54+00:00Added an answer on June 14, 2026 at 3:59 pm

    Generally, this clipping is due to zooming using the scale limits (which drop points outside the range) versus using the coord limits (which is a true zoom, just drawing the parts inside with the parts outside the range still there). ggmap does not have a straightforward way to indicate the second type of zoom should be used, but looking at the function, the relevant parts can be pulled out and put back together:

    s12 <- get_map(maptype = "satellite", zoom = 12) 
    ggmap(s12, base_layer=ggplot(aes(x=lon,y=lat), data=zips),
          extent = "normal", maprange=FALSE) +
        geom_polygon(aes(x = lon, y = lat, group = plotOrder),
                     data = zips, colour = NA, fill = "red", alpha = .5) +
        geom_path(aes(x = lon, y = lat, group = plotOrder),
                  data = zips, colour = "white", alpha = .7, size = .4) +
        coord_map(projection="mercator", 
                  xlim=c(attr(s12, "bb")$ll.lon, attr(s12, "bb")$ur.lon),
                  ylim=c(attr(s12, "bb")$ll.lat, attr(s12, "bb")$ur.lat)) +
        theme_nothing()
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Playing round with Timers. Context: a winforms with two labels. I would like to
Am playing with Google Maps V3 API and StyledMarkers. The data is derived from
Playing with Erlang, I've got a process-looping function like: process_loop(...A long list of parameters
I'm using C# to pull spatial data from a sql server 2008 database. I'm
Playing with new RTTI module, I couldn't find a way to set an event
Playing around with Flask and just wanted to print out some data as JSON
So imagine a Sims-like 2D game for a touch based mobile phone where one
Just playing around with different types of bindings and having a property binding a
Playing with Ruby and Ruby-Pandoc. Seems like a nice tool, if I can get
For playing quick sounds I prefer SystemSound over AudioPlayer because load time is quicker.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.