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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:16:42+00:00 2026-06-10T01:16:42+00:00

I have asked about the same issue from here and here , but still

  • 0

I have asked about the same issue from here and here, but still can’t get my problem solved. I think I need to bring the whole problem and ask for help, rather than breaking it down into small parts.

I have a dataframe which I exported it to csv and can be found at http://pastebin.com/SNT9Ykt7.

chart <- ggplot(data=map.shp,aes(x=long,y=lat))

### PART1 START ###
chart <- chart + geom_polygon(data=map.shp,aes(x=long,y=lat,group=id),colour=rgb(162,159,140,maxColorValue=255),fill=rgb(233,235,232,maxColorValue=255),size=0.1)
### PART1 END ###

### PART2 START ###    
map.group <- unique(map.shp[,"group"])
for (loop in (1:length(map.group))) {
  temp.shp <- map.shp[map.shp[,"group"]==map.group[loop],]
  temp.colour <- "red"
  if (unique(temp.shp[,"hole"])=="TRUE") {
    temp.colour <- "blue"
  }
  chart <- chart + geom_polygon(data=temp.shp,aes(x=long,y=lat,group=id,order=group),colour=rgb(162,159,140,maxColorValue=255),fill=temp.colour,size=0.1)
}
### PART2 END ###

chart <- chart + opts(panel.background=theme_rect(colour=rgb(190,225,247,maxColorValue=255),fill=rgb(190,225,247,maxColorValue=255)),                      
                      panel.grid.major=theme_blank(),
                      panel.grid.minor=theme_blank(),
                      panel.border=theme_blank(),
                      plot.background = theme_blank(),
                      axis.line=theme_blank(),
                      axis.text.x=theme_blank(),
                      axis.title.x=theme_blank(),
                      axis.text.y=theme_blank(),
                      axis.title.y=theme_blank(),
                      axis.ticks=theme_blank())
chart <- chart + coord_cartesian(xlim = range(map.shp[,"long"]), ylim = range(map.shp[,"lat"]))

PART1 script gives me this output:

enter image description here

PART2 script gives me this output:

enter image description here

Actually this is a piece land with some hole on it, I will have something else shown under this layer so that I must present the hole as “hole”, so display using PART2 script is not possible. But PART2 script is plotting the map correctly (red as land, blue as hole).

A few problems from PART1 output that I need to fix:

  • some part of the hole not presented as hole
  • line outside the polygon is plotted wrongly

I don’t know what have I done wrong in PART1. Can anyone help?

update 01

The txt file is created using the following code:

map.shp.raw <- readShapeSpatial("shp_files/map.shp")
map.shp <- fortify(map.shp.raw)

The txt file attached can be saved as txt and import as data.frame using read.table command.

  • 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-10T01:16:44+00:00Added an answer on June 10, 2026 at 1:16 am

    With a nod to @spacedman, who said:

    The solution I came up with years ago for drawing holes is to make
    sure that after each hole your x,y coordinates return to the same
    place. This stops the line buzzing all around and crossing other
    polygons and leaving open areas that the winding number algorithm
    doesn’t fill (or does fill when it shouldn’t).

    (In https://stackoverflow.com/a/12051278/602276)

    So, let’s follow his advice:

    library(plyr2)
    map.shp2 <- ddply(map.shp, .(piece), function(x)rbind(x, map.shp[1, ]))
    ggplot(data=map.shp2) + geom_polygon(aes(x=long,y=lat))
    

    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 asked a question about manytomanyfield here which i solved but now a
I am experiencing the same problem as many people have asked about before, where
I know similar questions have been asked, but I'm not sure about the answers
I have asked a question about how to retrieve data from different tables in
I have asked this question in a different post here on SO: How can
I asked a question earlier on this same project but I'm still having issues
I asked the almost the same question before also, but i have not yet
I have asked the same question for some days on oracle forums, but no
This question have been asked by several people but my problem seems to be
I have already asked a question about this, but the problems keeps on hitting

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.