R 绘制带有几何点(纬度)注释1至19的ggmap。点数据位于CSVfile中
我正在使用R 绘制带有几何点(纬度)注释1至19的ggmap。点数据位于CSVfile中,r,csv,ggplot2,legend,ggmap,R,Csv,Ggplot2,Legend,Ggmap,我正在使用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,
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")
这里有一种方法。我使用base R中的
transform
为文本注释创建了新的lat。我使用geom_text
添加所需的标签。我使用scale\u color\u discrete
更改图例的名称
library(ggmap)
library(ggplot2)
### Get a map
map <- get_map(location=c(lon=34.832, lat=0.852), color="color",
source="google", maptype="terrain", zoom=9)
### Create new lat for annotation position
mydf2 <- transform(mydf,lat2 = lat + 0.05)
ggmap(map) +
geom_point(data = mydf2, aes(x = long, y = lat, color = Name_of_Organization)) +
geom_text(data = mydf2, aes(x = long, y = lat2, label = ORGANIZATION_ID), size = 3) +
scale_colour_discrete(name = "Name of Organization")
库(ggmap)
图书馆(GG2)
###拿张地图
我很感激爵士乐队的尝试。然而,它用彩色键打印地图。你能知道如何用数字制作相同的图例吗?例如“组织ID”如下:图例:点名称1=Kitale 2=Chereng'any 3=Kaplamai 4=Ndalu 5=Tongaren@WachiyeEmmanuel我更新了我的建议。如果要更改图例元素的顺序,也可以这样做。现在,顺序是按字母顺序排列的。
library(ggmap)
library(ggplot2)
### Get a map
map <- get_map(location=c(lon=34.832, lat=0.852), color="color",
source="google", maptype="terrain", zoom=9)
### Create new lat for annotation position
mydf2 <- transform(mydf,lat2 = lat + 0.05)
ggmap(map) +
geom_point(data = mydf2, aes(x = long, y = lat, color = Name_of_Organization)) +
geom_text(data = mydf2, aes(x = long, y = lat2, label = ORGANIZATION_ID), size = 3) +
scale_colour_discrete(name = "Name of Organization")
mydf <- structure(list(ORGANIZATION_ID = 1:5, lat = c(0.988597, 0.981345,
1.019304, 0.840672, 0.78183), long = c(35.124259, 35.219947,
35.040037, 34.994145, 34.965753), Name_of_Organization = structure(c(3L,
1L, 2L, 4L, 5L), .Label = c("2 = Chereng'any", "3 = Kaplamai", "1 = Kitale",
"4 = Ndalu", "5 = Tongaren"), class = "factor")), .Names = c("ORGANIZATION_ID",
"lat", "long", "Name_of_Organization"), class = "data.frame", row.names = c(NA,
-5L))
# ORGANIZATION_ID lat long Name_of_Organization
#1 1 0.988597 35.12426 1 = Kitale
#2 2 0.981345 35.21995 2 = Chereng'any
#3 3 1.019304 35.04004 3 = Kaplamai
#4 4 0.840672 34.99415 4 = Ndalu
#5 5 0.781830 34.96575 5 = Tongaren