1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| library(maptools) library(ggplot2)
getwd() setwd("/home/silen/R _Data/Map")
map <- readShapePoly("countries_shp/countries.shp")
names(map) str(map$NAME) table(map$EU)
DB <- fortify(map) p <- ggplot(DB, aes(x=long,y=lat, group = group))
World <- p + geom_polygon(color="white", fill = "grey") + theme(panel.grid.major=element_blank(), panel.background=element_blank(), axis.title.x=element_blank(), axis.title.y=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.line=element_blank(), axis.ticks=element_blank())+ ggtitle("World")+ scale_y_continuous(breaks = (-2:2) * 30) + scale_x_continuous(breaks = (-4:4) * 45) + coord_map("lagrange")
DB <- fortify(map, region = "NAME")
head(DB) names(DB)[c(1, 2)] = c("x", "y")
mor <- read.csv("mapRate.csv",head =T, sep =",") epi <- data.frame(id = unique(sort(DB$id))) epi <- merge(epi, mor, by.x= "id", all.x = T)
p1 <- ggplot(epi, fill = "#595959") + geom_map(aes(map_id = id, fill = rate ), colour = "white", map = DB) + expand_limits(DB) + theme(panel.grid.major = element_blank(), panel.background = element_blank(), plot.background = element_rect(fill = "transparent",colour = NA), legend.background = element_rect(fill = "transparent",colour = NA), legend.title = element_blank(), axis.title.x = element_blank(), axis.title.y = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank(), axis.line = element_blank(), axis.ticks = element_blank())+ scale_fill_gradient(high = "#F70909", low = "#E99799") + scale_y_continuous(breaks = (-2:2) * 30) + scale_x_continuous(breaks = (-4:4) * 45) + coord_map("lagrange")
png('world.png',width=600,height=600,units="px",bg = "transparent") print (p1) dev.off()
|