2

I am trying to colorize some countries in one color,using ggmap like this:

enter image description here

The countries I want to colorize are:

Japan

People's Republic of China
Republic of Korea
Socialist Republic of Viet Nam
Republic of Indonesia Kingdom of Thailand Democratic Socialist Republic of Sri Lanka
Taiwan
People's Republic of Bangladesh
Federal Democratic Republic of Nepal
India Mongolia
Union of Myanmar
Republic of the Philippines Republic of Singapore Kingdom of Cambodia Malaysia
Islamic Republic of Pakistan
Lao People's Democratic Republic
Brunei Darussalam Kingdom of Bhutan

Islamic Republic of Afghanistan
Islamic Republic of Iran
Republic of Yemen
United Arab Emirates
Republic of Lebanon State of Israel
Republic of Kenya
Republic of Botswana
Federal Democratic Republic of Ethiopia
Federal Republic of Nigeria Republic of Mozambique
Republic of Uganda
Kingdom of Morocco Republic of Ghana
Republic of South Africa
Republic of Zimbabwe
United States of America
Canada
United Mexican States Federative Republic of Brazil
Republic of Guyana
Antigua and Barbuda
Republic of Cuba
Republic of Nicaragua
Republic of the Fiji Islands
Australia
Kingdom of Tonga
Independent State of Samoa Independent State of Papua New Guinea
Subtotal
Republic of Uzbekistan
Kingdom of Norway
Kyrgyz Republic
Federal Republic of Germany French Republic
Republic of Tajikistan
Republic of Austria
Republic of Italy
United Kingdom

Kingdom of Denmark
Kingdom of Sweden
Republic of Finland Republic of Estonia Republic of Lithuania
Russian Federation
Georgia
Kingdom of the Netherlands
Portuguese Republic Republic of Iceland Republic of Kazakhstan
Republic of Moldova Republic of Poland
Spain
Swiss Confederation
Ukraine

I would be grate if you teach me how to do this.

A.L
  • 10,259
  • 10
  • 67
  • 98
Serendipity
  • 69
  • 1
  • 7
  • 2
    I suggest you provide a reproducible example (can be only a few countries). We need to see how the data is structured. I suspect a tool called "regular expressions" will be handy to find countries and create another variable that designates color. – Roman Luštrik Jan 17 '15 at 09:58

1 Answers1

1

You appear to want a choropleth, which is a map where the countries (in this case) are colored by a scale that indicates something. So, if your scale were percentage of literate adults in each country, you would have that percentage in a variable and the choropleth will apply the color gradient you choose (or use a default palette) so that the color matches the percentage. Take a look at Plotting bar charts on map using ggplot2? as well as https://stackoverflow.com/questions/24130669/map-with-ggplot2-putting-data-in-wrong-geographic-location There is also a package: choroplethr

This answer is excellently done: Region polygons not displaying in ggplot2 Choropleth map

Here is a part of an example of doing this with ggplot where I have not necessarily included all the prep work of picking the map itself:

states_map <- map_data(map="state")  # another choice is "usa"
states_map$region <- as.character(states_map$region)

ggplot(acq.jds.color, aes(map_id = region, fill = StLawyers)) + 
  geom_map(map = states_map) + 
  scale_fill_gradient2(low = "#559999", mid = "grey90", high = "#BB650B", midpoint = median(acq.jds.color$StLawyers)) +
  expand_limits(x = states_map$long, y = states_map$lat) +
  coord_map("mercator") +
  labs(x = "", y = "") +
  theme(axis.text = element_blank(), panel.background = element_blank(), panel.grid = element_blank(), 
        axis.ticks.length = unit(0, "cm"), axis.ticks.margin = unit(0, "cm"), panel.margin = unit(0, "lines"),
        plot.margin = unit(c(0,0,0,0), "lines"), complete = TRUE)
Community
  • 1
  • 1
lawyeR
  • 7,488
  • 5
  • 33
  • 63
  • Thank you for the comment. Is it possible to paint those countries in only one color and not making choropleth? Choropleth seems hard for me to make since I do not have any expertise in R. – Serendipity Jan 17 '15 at 11:21
  • Yes. In essence you would need to add a column to your data frame. Perhaps call it "color". Each country that you want to be the color you would have a "T" for true in "color". Then you fill the countries by that column and all T's will be the same. – lawyeR Jan 17 '15 at 11:24
  • This is the first time for me to use ggmap, so I have no idea how to do it. I have to learn from scratch. Thank you for your cooperation. – Serendipity Jan 17 '15 at 12:04