library(maps) library(mapdata) library(ggplot2) map("state") map("france") map("nz") map("state", fill=T, col=rainbow(10)) map("usa") map( ) mn.nd.sd <- c("minnesota", "north dakota", "south dakota") map("state", mn.nd.sd) map("state", "illinois") states_map <- map_data("state") ggplot(states_map, aes(x=long, y=lat, group=group)) + geom_polygon(fill="white", colour="black") world_map <- map_data("world") east_asia <- map_data("world", region=c("Japan", "China", "North Korea", "South Korea")) ggplot(east_asia, aes(x=long, y=lat, group=group, fill=region)) + geom_polygon(colour="black") + scale_fill_brewer(palette="Set2") # plot New Zealand from world map nz1 <- map_data("world", region="New Zealand") nz1 <- subset(nz1, long > 0 & lat > -48) # trim off islands ggplot(nz1, aes(x=long, y=lat, group=group)) + geom_path( ) # Plot New Zealand from nz map. nz2 <- map_data("nz") ggplot(nz2, aes(x=long, y=lat, group=group)) + geom_path( ) # Creating a choropeleth map crimes <- data.frame(state=tolower(rownames(USArrests)), USArrests) crimes states_map <- map_data("state") crime_map <- merge(states_map, crimes, by.x="region", by.y="state") head(crime_map) library(plyr) crime_map <- arrange(crime_map, group, order) head(crime_map) # Need mapproj package for next statements. ggplot(crime_map, aes(x=long, y=lat, group=group, fill=Assault)) + geom_polygon(colour="black") + coord_map("polyconic") ggplot(crime_map, aes(x=long, y=lat, group=group, fill=Assault)) + geom_polygon(colour="black") + scale_fill_gradient2(low="#559999", mid="gray90", high="#BB650B", midpoint=median(crimes$Assault)) + expand_limits(x=states_map$long, y=states_map$lat) + coord_map("polyconic")