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

  • Home
  • SEARCH
  • 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 7863569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:31:34+00:00 2026-06-02T23:31:34+00:00

I am trying to take a shapefile and points that are contained within it

  • 0

I am trying to take a shapefile and points that are contained within it and end up with a plot of the shapefile, the points, and then eventually a quadrat analysis overlayed on top with some amount of alpha transparency.

I tried and came up with this example that should serve:

library(ggplot2)
library(maps)
library(maptools)
library(spatstat)
library(plyr)

# generate polygons
usa <- map('usa', plot=F)
IDs <- sapply(strsplit(usa$names, ':'), function(x) x[1])
crs <- CRS('+proj=longlat +ellps=WGS84')
usa.sp <-map2SpatialPolygons(usa, IDs=usa$names, proj4string=crs)
usa.pts <- fortify(usa.sp, region="id")

base.plot <- ggplot(usa.pts, aes(x=long, y=lat)) +
              geom_path(aes(group=id)) +
              coord_equal()

# generate point process
lon <- runif(5000, min(usa.pts$long, na.rm=TRUE), max(usa.pts$long, na.rm=TRUE))
lat <- rnorm(5000, mean(usa.pts$lat, na.rm=TRUE), sd=sd(usa.pts$lat, na.rm=TRUE)/2)
points <- data.frame(lon, lat)
points.sp <- SpatialPoints(points, proj4string=crs)
points <- points[which(!is.na(over(points.sp, usa.sp))),]

# the first plot
base.plot +
  geom_point(data=points, aes(x=lon, y=lat), color="red", alpha=I(0.5))

So then what my shapefile and data would roughly look like are:
enter image description here

The next steps I’d like to take are to perform quadrat analysis of various cell sizes and plot the results over the plot with points. Assuming I successfully get a quadratcount object (wrangling the data right now into right format), how would I go about plotting it as a heatmap-like overlay?

  • 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-02T23:31:36+00:00Added an answer on June 2, 2026 at 11:31 pm

    To add a heatmap in ggplot, you can use geom_tile, or its default stat, stat_bin2d:

    library(mapproj)
    base.plot +
      stat_bin2d(data=points, aes(x=lon, y=lat), bins=100) +
      coord_map()
    

    I also suggest you use coord_map rather than coord_equal, after installing the mapproj package to enable different map projections.

    enter image description here

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

Sidebar

Related Questions

I am trying to take a shapefile of subdivisions within a county that I
I'm trying to take the contents of a div within an iframe, delete the
I am trying to take a string that has HTML, strip out some tags
I'm trying to take an ADO Recordset and then loop through it to parse
Trying to take a string of tags and only save the first 10 that
I'm trying to take an integer as a parameter and then use recursion to
So I'm trying to take the variable that increments in a for statement, and
I'm trying to take all the <select> elements within a particular <div> and capture
I'm trying to take a group of photos (with the addition that more photos
I am trying to take a decimal and convert it so that I can

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.