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 8506615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:38:20+00:00 2026-06-11T02:38:20+00:00

I have analysed a dataset of GPS points using density.ppp to generate a sort

  • 0

I have analysed a dataset of GPS points using density.ppp to generate a sort of heatmap of intensity of the points, as shown below:

enter image description here

However, I would like the image to be limited to the borders of the shapefile, similar to below:

enter image description here

The first image is called as

x <- readShapePoly("dk.shp")
xlim<-c(min(912),max(920))
ylim<-c(min(8023),max(8030))
a<-ppp(cases@coords[,1], cases@coords[,2], xlim, ylim, unitname=c("km"))
plot(density.ppp(a, 0.1), col=COLORS)
plot(x, add=T, border="white")

where cases@coords are the GPS coordinates of each point of interest, and x is a shapefile which provides the outline for the geographical unit.

The second image is called using this code:

plot(x, axes=T, col=COLORS, border="White")

Does anyone know how this might be done? Perhaps it’s not possible with plot() and I will need another package.

As an aside, the next step I plan to do will be to overlay this image over a map imported from GoogleEarth. I’m not yet sure how to do that either, but will post the answer if and when I work it out

many thanks

  • 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-11T02:38:22+00:00Added an answer on June 11, 2026 at 2:38 am

    The result of density.ppp has a matrix (v) that contains the information, if the points outside of the polygon of interst are changed to NA before it is plotted then they will not plot. Here is an example of doing this:

    library(maptools)
    library(sp)
    library(spatstat)
    
    xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
          IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
    
    x <- rnorm(25, -80, 2)
    y <- rnorm(25, 35, 1 )
    
    tmp <- density( ppp(x,y, xrange=range(x), yrange=range(y)) )
    plot(tmp)
    plot(xx, add=TRUE)
    points(x,y)
    
    tmp2 <- SpatialPoints( expand.grid( tmp$yrow, tmp$xcol )[,2:1],
        proj4string=CRS(proj4string(xx)) )
    
    tmp3 <- over( tmp2, xx )
    
    tmp$v[ is.na( tmp3[[1]] ) ] <- NA
    
    plot(tmp)
    plot(xx, add=TRUE)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're using SQL Server 2000 Query Analyser, and one issue we have is that
Have deployed numerous report parts which reference the same view however one of them
At the moment I have ResultsCollection = List<MyDataStructure>; which is then analysed with LINQ
I am going to develope application using jira 4.0 api. I have analyzed a
I have a large dataset of philosophic arguments, each of which connect to other
For statistical reasons, I want an extensive analysis from a dataset. I already have
I have this code which I have analysed in Firebug and it is really
Yes, I know that my problem is not the unique, but I have analysed
Regular expressions have never been one of my strong points, and this one has
I was going through the process of serialization and what I have analysed is

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.