I want to plot a world map using ggplot2 (v.9) which combines two pieces if information. The following example illustrates:
library(rgdal)
library(ggplot2)
library(maptools)
# Data from http://thematicmapping.org/downloads/world_borders.php.
# Direct link: http://thematicmapping.org/downloads/TM_WORLD_BORDERS_SIMPL-0.3.zip
# Unpack and put the files in a dir 'data'
gpclibPermit()
world.map <- readOGR(dsn="data", layer="TM_WORLD_BORDERS_SIMPL-0.3")
world.ggmap <- fortify(world.map, region = "NAME")
n <- length(unique(world.ggmap$id))
df <- data.frame(id = unique(world.ggmap$id),
growth = 4*runif(n),
category = factor(sample(1:5, n, replace=T)))
## noise
df[c(sample(1:100,40)),c("growth", "category")] <- NA
ggplot(df, aes(map_id = id)) +
geom_map(aes(fill = growth, color = category), map =world.ggmap) +
expand_limits(x = world.ggmap$long, y = world.ggmap$lat) +
scale_fill_gradient(low = "red", high = "blue", guide = "colorbar")
However, this solution is not a nice way to display both growth
and category
. Growth
is highly visible, but category
is almost impossible to see because it is just a border.
I have tried to increase the size of borders, but without luck (the new geom_map is hard to work with). Does anyone knows how to increase border size in the above example, or even better, a mechanism to display two factors?
A bonus question: country names, such as those used by the maps package (which features USSR!) are the data used in the example is fragile. I prefer to use ISO 3166-1 alpha-3(1). Does anyone know data readily usable with ggplot2 which features ISO-... country names (included in linked data)
Result: