I am quite new to GIS using R.

I have two sets of data, upon which I could create two polygons like this: enter image description here

What I want to do is colour the common area (inner 'circle') and the space between borders. However, if I fill the two polygons directly, the colour for the outer polygon simply overlayed the inner polygon. Is there any way to do this nicely? My codes are:

ggplot()+ geom_polygon(data = inter_Coords, aes(x = inter_Coords[,1], y 
= inter_Coords[,2],alpha = 0.25)) + 
geom_polygon(data = concave_pts, aes(x = concave_pts[,1], y = 
concave_pts[,2], alpha = 0.25)) +
geom_polygon(data = diff_Coords, aes(x = diff_Coords[,1], y = 
diff_Coords[,2], fill = 'yellow', alpha = 0.25))

Results are: enter image description here

  • "What I want to do is colour the common area (inner 'circle') and the space between borders" - you seem to have done that, the common area is dark brown and the space between borders is light brown, unless I've misunderstood what you mean. Can you draw a picture of what you want and edit this into your question – Spacedman Jul 8 '19 at 7:15
  • The reason that the inner area is dark is that two same colors are overlapped. And I want the inner color to be, let's say, yellow and outer to be blue (two distinct color way) – HAOYANG MI Jul 8 '19 at 14:33
  • So why are you setting alpha and making the colours transparent? Plot the larger one in blue then add the smaller one in yellow, don't set alpha to anything. You'll get a blue ring and a yellow inner polygon. – Spacedman Jul 8 '19 at 14:42
  • And take the fixed settings outside the aes call, ie like: geom_polygon(..., aes(x=..y=..), col="yellow") – Spacedman Jul 8 '19 at 14:46
  • 1
    Perhaps the easiest solution is to use some of the geometric operators to construct the difference between the two objects. sf::st_difference or rgeos::gDifference depending on your data. – Spacedman Jul 8 '19 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.