【发布时间】:2015-02-05 04:09:23
【问题描述】:
我正在使用ggmap 和ggplot2 使用geom_point 进行绘图。我也想在点附近添加注释文本(即 1 到 19)。
这是我的代码:
setwd("../Documents/MAPS")
library(ggplot2)
library(mapproj)
library(maps)
library(maptools)
library(rgdal)
library(ggmap)
library(sp)
bdl_sites <- get_map(location =c(lon = 34.832, lat = 0.852), colour = "colour",
source = "google", maptype = "terrain", zoom = 9)
save(bdl_sites, file = "bdl_sites.rda")
load(file = "bdl_sites.rda")
BDL_Org_Data.csv <- read.csv("BDL_Org_Data.csv")
BDL_Org_DataF.csv <- fortify(BDL_Org_Data.csv, region = "ORGANIZATION_ID")
ggmap(bdl_sites) +
geom_point(data = BDL_Org_DataF.csv, aes(x = long, y = lat),
colour = "red", size = 2, alpha = .5) +
annotate("text", x=BDL_Org_DataF.csv$long, y=BDL_Org_DataF.csv$lat,
label = BDL_Org_DataF.csv$ORGANIZATION_ID, size = 2, position = "right") +
labs(title = "MAP FOR BDL PROJECT SITES") +
labs(x = "Longitude", y = "Latitude")
帮助在图例中显示点编号和名称!
感谢 BattleHamster 改进了我的问题。这是我第一次在这个网站上发帖,但我通过这个网站学到了很多东西。我实际上希望在 ggmap 中显示 geom_Points 注释为 1,2,3,最多 19。然后显示“1”的图例及其对应的名称“Kitale”如下所示:
Legend: Point Names
1=Kitale
2=Chereng'any
3=Kaplamai
4=Ndalu
5=Tongaren
.
.
.
19=Kiminini
The Points data is in a CSV file in the format below
ORGANIZATION_ID lat long Name_of_Organization
1 0.988597 35.124259 Kitale
2 0.981345 35.219947 Chereng'any
3 1.019304 35.040037 Kaplamai
4 0.840672 34.994145 Ndalu
5 0.78183 34.965753 Tongaren
【问题讨论】:
标签: r csv ggplot2 legend ggmap