Apr 16, 2013

Plotting data over a map with R

After searching for a few hours on the web, I’ve been able to get my R code working and plot breast cancer data on a world map. It might not the best looking map possible (R graphics is incredible!), but I am happy with that for now.

To produce the map I used the “maps” package available through CRAN repository. And of course I needed longitude and latitude coordinates for each country, which I searched on the web and added to my original data set. Here are the steps I followed:

1) Load a .csv file containing lat/long coordinates for all countries

> countryCoord<- read.csv (“~/Rworkdir/data/countryCoord.csv”)

2) Add lat/long coordinates to my original breast cancer data set (dataset is called “gapCleaned”). To do this I used the function “merge”, specifying to merge the two data sets by the variable “country” (both the datasets have this variable in common), and used left outer join (here is a good explanation of merge command)

> mergedCleaned<- merge(gapCleaned, countryCoord, by=”country”, all.x=TRUE)

All right, now I have two new columns in my data set, indicating lat and long coordinates for each country :) Cool, next step is finally drawing a map with the data.

3) Draw a world map and tell R where to plot breast cancer data

> library(maps)

> map(“world”,col=”gray90”, fill=TRUE)


I size the breast cancer symbol according to breast cancer value for each country in my data set

> radius <- 3^sqrt (mergedCleaned$breastcancer)

Finally, I give R instructions to plot my breast cancer data over the world map

> symbols(mergedCleaned$lon, mergedCleaned$lat, bg = “blue”, fg = “red”, lwd = 1, circles = radius, inches = 0.175, add = TRUE)

                    New cases of breast cancer in the world, 2002


I am sure we can do prettier plots with R (I know there are other interesting packages suitable for this, such as ggplot), but I am happy for now. I’ve learned something new and been able to visualize and communicate data in a more effective way than just a scatterplot.


Looking at the map, we can quickly identify the countries/areas with the highest number of breast cancer cases and hypothesize patterns. As reported on my last post, these are United States, New Zealand, Israel, Central/Northern Europe and in general highly developed economies rather than developing countries.


  1. Too that's exactly practically what i'll be doing later on. Now i am just actually seriously upbeat. I act like I only agreed to be put together. As being legitimate total, Training also offers you wide-ranging forces over the country's immigration law legal process of law. He takes on events along with solitary immigrants, While he performed here connected one mum to be coming via El Salvador. They be afraid of the exists including asylum hunters will are in danger if they are came back due in lands source..

    Every get to give cash flow but yet we make a {New Jordan Releases 2020} decision, And also just how we like to spend some money reads a good deal information on which are you're. One's own via shawls by hoda inthat would runners {Cheap MK Bags} during 2016 hinted at {New Yeezy Boost 350} the item about {Coach Outlet Clearance Sale} yourself: Plus level educational facilities together with social programs obtained falling apart, You're looking at to allocate specific tools to inspire hawaii legislature in orde

  2. I do accept as true with all the ideas youĂ­ve offered in your post. They are very convincing and can definitely work. Men Fashion Brown Leather Long Coat

  3. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Essay Editing Uk

  4. There are many Coach Outlet Online in the market.
    The best place to secure that you are really getting an authentic Michael Kors Bags Outlet is from the authorized stores.
    One of the primary concerns when buying a new Michael Kors Purse Outlet is that of authenticity.
    If you are smart and want full value for your money, then there are some ways in which you can identify an original Coach Outlet Store Online.
    Remember, the MK Outlet never comes off, and never tears out.
    Probably the best way to find out if the Coach Bags Clearance is actually.
    Time to go online and get yourself a Coach Bags Outlet if you haven't already.
    Cheap Real Yeezys, a Nike new product launched recent years, is one of them.
    Actually, there are many stores stocking Cheap Yeezys.

  5. website development services Seamlessly, developers are heading ahead to analyze and understand various programming languages

  6. Thanks for sharing this.,
    Leanpitch provides crash course in Brain hacks using NLP everyone can use it wisely.
    NLP training

    Brain hacks with NLP

  7. Thanks for sharing this.,
    Leanpitch provides crash course in Brain hacks using NLP everyone can use it wisely.
    NLP training

    Brain hacks with NLP

  8. Likert Scale is a very useful visualization to present the survey results. Can you shed light which tools are best and easy to use to draw 5 point Likert Scale . Read more articles here : https://businessanddigitalmarketing.blogspot.com/2021/07/how-effective-are-google-ads.html

  9. Great Blog...
    it's very knowledgeable information
    it's very effective for learner
    it solution company