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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:17:35+00:00 2026-06-12T18:17:35+00:00

I have a bunch of data which I’ve plotted at the county level, without

  • 0

I have a bunch of data which I’ve plotted at the county level, without borders. I’d like to add in state boundaries. I have a state shapefile (polygons), but spplot doesn’t seem to have any way to add on top of the previous map. Is there any way to do this without rewriting the panel function to take two SPDFs (which seems pretty specialized for what is likely a problem other people have)?

Here’s a reproducible example:

library(sp)
Srs1 = Polygons(list(Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2)))), "s1")
Srs2 = Polygons(list(Polygon(cbind(c(5,4,2,5),c(2,3,2,2)))), "s2")

county <- SpatialPolygonsDataFrame( SpatialPolygons(list(Srs1,Srs2)), 
                                  data.frame( z=1:2, row.names=c("s1","s2") ) )

SrsA <- Polygons(list(Polygon(cbind(c(3,5,5,1,3),c(3,4,6,5,3)))),"sA")
state <- SpatialPolygonsDataFrame( SpatialPolygons(list(SrsA)),
                                  data.frame( z=1,row.names="sA" ))

spplot( county, zcol="z",col=NA )
spplot( state, add=TRUE ) # Note the add=TRUE does nothing here, but that's the spirit of what I want to accomplish
  • 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-12T18:17:36+00:00Added an answer on June 12, 2026 at 6:17 pm

    To overplot using the spplot function, you can use the sp.layout argument. For example, create lists of the appropriate layout items, such as

    spCounty <- list("sp.polygons", county, col = NA)
    spState <- list("sp.polygons", state)
    

    Then plot, passing the above list items as a list to the sp.layout argument:

    # spplot(county, zcol = "z", col = NA, sp.layout = list(spCounty, spState))
    # actually, you only need to pass the second layout item to sp.layout
    spplot(county, zcol = "z", col = NA, sp.layout = spState)
    

    The x and y limits might not be correct if the two spatial data.frames don’t overlap completely. You can correct this if necessary by extracting the appropriate limits from bbox(obj)

    For example,

    theMin <- pmin(bbox(county)[,1], bbox(state)[,1])
    theMax <- pmax(bbox(county)[,2], bbox(state)[,2])
    
    spplot(county, zcol = "z", col = NA, sp.layout = spState,
      ylim = c(theMin[2], theMax[2]), xlim = c(theMin[1], theMax[1]))
    

    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 have a bunch of data formatted like this, which displays great in a
I have a django view generating a bunch of data which I want to
So in my app I have a bunch of data that I'd like to
I have a bunch of boolean options for things like acceptable payment types which
I have an ASPx Gridview control which displays a bunch of data. In the
Currently we have a table with a bunch of data from a database which
I have bunch of temporal data which I want to convert to RDF format.
I essentially have a bunch of data objects which map timestamps in milliseconds to
I have a bunch of files (almost 100) which contain data of the format:
I have a bunch of NVARCHAR columns which I suspect contain perfectly storable data

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.