Hi Kristoffer,
you can pull out the centroid of the largest polygon used in representing each country for a solution that would work in other applications. The key here is to convert to SpatialPolygons and then extract the stored coordinates which are calculated as part of the object definition. Example code below.
- Allan
R 2.15.0 x86_64-pc-mingw32/x64 (64-bit); ggplot2_0.9.0 maptools_0.8-14 sp_0.9-98
library(ggplot2)
library(maptools)
reg <- map_data("world")
P1 <- ggplot(reg, aes(long, lat)) +
geom_polygon(aes(group = group), show_guide=F)
worldmap <- map('world', fill=TRUE, col="transparent", plot=FALSE)
world_sp <- map2SpatialPolygons(worldmap, IDs=IDs,
proj4string=CRS("+proj=longlat +datum=wgs84"))
# coordinates pulls out the centroid of
#the largest (area) polygon for a country
world.label <- data.frame(
country = names(world_sp),
coordinates(world_sp))
head(world.label)
# plot with labels
P1 + geom_text(aes(X1, X2, label = country), data = world.label)