I am plotting with ggmap
and ggplot2
using geom_point
. I want to add annotation text (i.e., 1 to 19) close to the points as well.
Here is my code:
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")
Help show in legend Point numbers and names!
Thanks BattleHamster for improving my question. It is my first time to post on this site but I have learnt a lot through this site. I actually wish to display geom_Points in the ggmap annotated 1,2,3,up to 19. Then the legend to show "1" and its corresponding name "Kitale" like below:
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
Here is one approach. I created new lat for text annotation using
transform
in base R. I usedgeom_text
to add the labels you wanted. I usedscale_colour_discrete
to change the name of the legend.DATA