i trying generate generate plot of world map colour of each country corresponds particular value stored in data frame.
> aggregated_country_data country num_responses region 1 al 1 albania 2 1 armenia 3 ar 32 argentina ... 75 zw 3 zimbabwe
this have tried
library(rworldmap) library(ggplot2) map.world <- map_data(map="world") gg <- ggplot() gg <- gg + theme(legend.position="none") gg <- gg + geom_map(data=map.world, map=map.world, aes(map_id=region, x=long, y=lat), fill="white", colour="black", size=0.25) gg
that plots world map fine, next want add colour each country in proportion value 'num_responses' in aggregated_country_data
gg <- gg + geom_map(data=aggregated_country_data, map=map.world, aes(map_id=region, fill=num_responses), color="white", size=0.25) gg
but it's colour coding each of colours correspond country code rather value that's in column num_responses in aggregated_country_data.
it's clear there's ggplot2 i'm not getting, can't figure out is.
i appreciate input, brad
i figured out problem was, , has nothing ggplot2 or else doing. aggregated_country_data data frame has different names 'region' in map.world. input data (aggregated_country_data) uses 2 letter country code default converted country name (called 'region' in data frame) using countrycode r package, using different naming convention names exists in map.world. that's totally different problem.
library(rworldmap) library(ggplot2) map.world <- map_data(map="world") #add data want map countries map.world #in example, add lengths of country names plus offset map.world$name_len <- nchar(map.world$region) + sample(nrow(map.world)) gg <- ggplot() gg <- gg + theme(legend.position="none") gg <- gg + geom_map(data=map.world, map=map.world, aes(map_id=region, x=long, y=lat, fill=name_len)) gg <- gg + scale_fill_gradient(low = "green", high = "brown3", guide = "colourbar") gg <- gg + coord_equal() gg