尝试这样的事情。似乎对我有用。我认为你的一些经纬度坐标是错误的。当前的fill
颜色geom_point
设置为,Tot437
因此您可能需要更改它。
library(ggplot2)
library(rgdal)
africa <- readOGR("c:/test", layer = "Africa")
africa.map = fortify(africa, region="COUNTRY")
africa.points = read.table("c:/test/SPM-437-22Nov12.txt", header = TRUE, sep = ",")
names(africa.points)[which(names(africa.points) == 'Longitude')] <- 'long' # rename lat and long for consistency with shp file
names(africa.points)[which(names(africa.points) == 'Latitude')] <- 'lat'
ggplot(africa.map, aes(x = long, y = lat, group = group)) +
geom_polygon(colour = "black", size = 1, fill = "white", aes(group = group)) +
geom_point(data = africa.points, aes(x = long, y = lat, fill = Tot437, group = NULL), size = 4, shape = 21, colour = "black", size = 3)
顺便说一句,查看您的地图可能难以获得各个区域的详细视图,因此解决此问题的一种方法是通过子集,在这种情况下使用数据框。你可以这样做:
africa.map <- africa.map[africa.map$id == 'Madagascar', ]
africa.points <- africa.points[africa.points$Country == 'Madagascar', ]
ggplot(africa.map, aes(x = long, y = lat, group = group)) +
geom_polygon(colour = "black", size = 1, fill = "white", aes(group = group)) +
geom_point(data = africa.points, aes(x = long, y = lat, fill = Tot437, group = NULL), size = 2, shape = 21, colour = "black", size = 2)
...这应该会给你类似的东西: