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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:23:54+00:00 2026-05-27T04:23:54+00:00

I would like to plot a geographical map with n numbers of squares according

  • 0

I would like to plot a geographical map with n numbers of squares according to the frequency of a disease within a county. Like this one here:
enter image description here

But I couldn’t figure out how to do this with R or qGIS.
Thanks for y’all help.

  • 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-05-27T04:23:55+00:00Added an answer on May 27, 2026 at 4:23 am

    First write a little function called ‘stackbox’ that plots (using “rect”) the squares for the stack in the right place.

    Here’s the first line of that function:

    stackbox <- function(x,y,n,size,maxheight=5){
    
    • where ‘size’ is the height and width of the boxes, and ‘maxheight’ lets you have a stack that is 5 high or 10 high or whatever.

    Then call that function for every county that has cases.

    Where exactly were you stuck in the process?

    Here’s the function in full:

    stackbox <- function(x,y,n,size,maxheight=5,...){
      stackheight = seq(0,n,by=maxheight)
      stackheight=diff(unique(c(stackheight,n)))
    
      for(col in 1:length(stackheight)){
        xl=rep(x+(col-1)*size,stackheight[col]) - (length(stackheight)/2)*size
        yb=y+size*((1:stackheight[col])-1) - (max(stackheight)/2)*size
        xr=xl+size
        yt=yb+size
        rect(xl,yb,xr,yt,...)
      }
    }
    

    Example:

    plot(1:10)
    for(i in 1:10){
     stackbox(i,i,i,3,size=.1,col="red",border="white")
    }
    

    To do this on a map, you need the sp and maptools packages, and a shapefile or other geospatial data source that has your data in it:

    africa=readShapeSpatial(file.path(mapLib,"africa.shp"))
    plot(africa,border="gray")
    coords=coordinates(africa)
    for(i in 1:nrow(africa)){
      if(cases[i]>0){
        stackbox(coords[i,1],coords[i,2],africa$cases[i],1,border="#606060",col="#0083FE")
      }
    }
    

    Map using stacked boxes

    I’ve picked colours that look a bit like your original. Note that the boxes are in plot coordinates, so I had to make them 0.1 of a degree. You may wish to transform your map to a euclidean projection (using spTransform from package:gdal) and then they’ll be in those units and properly square.

    Doing nice text labels like in your original would be tricky though…

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

Sidebar

Related Questions

I would like a plot of the instantaneous phase difference between a frequency-swept drive
I would like to plot this kind of data: X axis: dates Y axis:
Suppose one would like to plot 2 sets of data with unequal number of
I would like to plot a time series that look like this: what I
I would like to plot discrete values in MATLAB like this: stairs() and stem()
I am using FullCalendar in one my projects and would like to plot recurring
I have a large real 1-d data set called r. I would like plot:
I would like to plot a vertical line (I'd prefer any orientation, but I'd
I would like to plot implicit equations (of the form f(x, y)=g(x, y) eg.
I would like to plot y1 and y2 in the same plot. x <-

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.