last day (16 days later) » 

4:56 PM
2
A: Plot only outer border in ggplot2 map / geom_polygon

Cyrus MohammadianThe basic idea is simple: you need to map fill and color to the aesthetics of the whole plot and then just map color to the aesthetics of the smaller polygon, that way you can color the smaller polygon with the same color as that of the larger polygon. That's what gets rid of the inside lines of ...

 
Thanks! But this doesn't quite work for me; the result I'm getting is this: imgur.com/a/DswP0. I'm using dplyr v0.5 & ggplot2 v2.1.0. Maybe it would help if you could elaborate a bit on your thought process behind the code.
 
@Felix, not sure what to tell you. I would suggest clearing your workspace and trying it again. I used the data you provided and ran the code via RStudio and R and I also ran it on my workstation and labtops (both mac) -everything works fine....You might have a ggplot2 extension or theme loaded in your environment so check that as well. The basic idea is simple: you need to map fill and color to the aesthetics of the whole plot and then just map color to the aesthetics of the smaller polygon, that way you can color the smaller polygon with the same color as that of the larger polygon...
...thats what gets rid of the inside lines of the smaller polygon. Then I added size outside of the aesthetics of the smaller polygon in order to increase the width of the red line to a perceptible level.
Also, I found this a little odd, I wasnt able to reproduce the map you posted in your original post with the code you supplied. I found that a little curious. Also tried that on multiple environments. Either there's something off about your R environment or you haven't actually run the code your posting...
If your problem recreating the plot above persists I would suggest moving to a new environment. If you cannot reproduce the plot you posted in your comment above (i.e. you're able to reproduce mine using the code I supplied) on a friend's or colleagues computer then I urge you to accept my solution so the question is resolved and then open up a new question in regards to why you're unable to reproduce such graphs in your own R environment (before doing that consider deleting R and reinstalling it).
@Felix see my updates
 
thanks, I really appreciate the time you're taking to help me with this. It is indeed odd. I can replicate my own plot perfectly, but I'm still having trouble to get your code working (using a clean environment and all). Your explanation makes perfect sense, so the problem is indeed likely to be related to my R installation. I'll give it a try on my home laptop tonight; if I can replicate your code, I'll accept the answer & open a new one. Which ggplot version are you using?
 
@Felix No problem, the same one you are, I've updated my post to include my sessionInfo.
 
so I've tried to run your code on my home laptop (also a Windows machine) with different dplyr & ggplot2 versions. The result is still the same as above, i.e. imgur.com/a/DswP0. I'm sending the code to some colleagues to see what results they are getting and report back.
 
4:56 PM
Honestly I dont know what to say, I find that near impossible...I had someone who never had R installed on the computer (ever) and who knows absolutely nothing about R run my code after installing R on his windows and on his Ubuntu. He was able to recreate the plot using my code. I was also able to to create that same plot on my 2012 el capitan mac and on my desktop mac 2015 el capitan
It would be nice if other SO users would check it out and confirm but this question wont come up on their feed again. I urge you to accept my solution and then open up a new question on SO. Then, link this current question to the new one you post and explain that you are unable to recreate the plot...that way we can get a pool of users testing out the code in different environments. The above code has now been tested on a Mac, Ubuntu, and Windows. Both mac environments and ubuuntu were successful and at least one windows environment was able to recreate this while two were not.
after reviewing meta stack, it's come to my attention that editing a question can increases the visibility of the question. Perhaps make a cosmetic change to the question so it makes the feed again.
I just tried my code on rollapp.com -it's a site with an online Rstudio console. You can run more or less anything from it. I just tested it and it recreated the same exact image I've posted above see imgur.com/a/9Y7wm?third_party=1. You will notice in that image that 1) its the same one I posted above (twice) and 2) that Rstudio is running outa my browser (the rollapp.com). I suggest you go to that site and try it. I've now shown that my code works in 5 different consoles across 4 different operating systems. I am in disbelief you cannot get it to work on your computer or laptop...
 
I managed to get the map you posted when I export the plot through a Cairo Device or directly as PDF. I'm pretty certain it's a bug in my R version (you're on a newer one) and I've planned an update anyway. So that's what I am going do. Thanks again for your time and effort for helping out with this one.
I've accepted your answer & added your explanation from the comments to the answer, so the idea behind your code is clear.
 
glad you got it to work! Ok so I usually dont put this much effort into figuring out questions on SO but I'm really interested in how you got the data (not necessarily the ethnic data -assuming GeoEPR? just the grid of Sudan for example or any country...). I followed the link you posted to PRIO -but the format doesnt seem to match the output data you posted -the data I downloaded was the world grid. I didnt notice any id that identified whether the grid was in a particular country.
So I'm curious how do I go from what I downloaded from their site to what you posted as data? Any information on that would be tremendously helpful for me! Thanks so much! and good luck with your work!
 

  last day (16 days later) »