在地图上绘制坐标 [英] Plot coordinates on map
问题描述
我正在尝试使用R来绘制我的坐标。我已经尝试过遵循不同的帖子( R:绘制世界地图上的分组坐标; 绘制R中谷歌地图上多个点的坐标),但是我的数据没有太大的成功。
我试图用我的gps坐标作为彩色圆点(每个区域具有特定的颜色)来实现世界的平面地图:
区域lat long
Agullhas -38,31 40,96
极地-57,59 76,51
塔斯马尼亚语-39, 47 108,93
library(RgoogleMaps)
lat < - c(-38.31,-35.50)#定义我们地图的ylim
lon < - c(40.96,37.50 )#定义我们地图的xlim
center = c(mean(lat),mean(lon))#tell以$ b $为中心的点b zoom< - 2 #zoom:1 =最远(整个球体),更大的数字=靠近
terrmap< - GetMap(center = center,zoom = zoom,maptype =satallite,destfile =satallite.png)
问题现在我不知道如何添加我的点数,我会为每个区域选择一种颜色。
任何人都可以帮助我继续前进吗?
我试过的其他选项是:
library(maps )
library(mapdata)
library(maptools)
map(database =world,ylim = c(-38.31,-35.5),xlim = c(40.96,37.5),col =grey80,fill = TRUE,projection =gilbert,orientation = c(90,0,225))
lon <-c(-38.31,-35.5)#fake经度向量
lat < ; -c(40.96,37.5)#fake纬度向量
坐标< - mapproject(lon,lat,proj =gilbert,orientation = c(90,0,225))#convert指向投影纬度/长
点(coord,pch = 20,cex = 1.2,col =red)#plot转换点
但坐标以错误的位置结束,我不确定为什么
希望有人可以帮忙
ggplot2 $ c
$ b #加载所需的软件包
库(ggplot2)
库(ggmap)
创建一个包含经纬度点的样本data.frame
lon <-c(-38.31, - 35.5)
lat < - c(40.96,37.5)
df < - as.data.frame(cbind(lon,lat))
#获取地图
mapgilbert< - get_map(location = c(lon = mean(df $ lon),lat = mean(df $ lat)),zoom = 4,
maptype =satellite,scale = 2)
#绘制地图上的一些点
ggmap(mapgilbert)+
geom_point(data = df,aes(x = lon,y = lat,fill =red ,alpha = 0.8),size = 5,shape = 21)+
guides(fill = FALSE,alpha = FALSE,size = FALSE)
你会得到这样的结果:
I am trying to plot my coordinates using R. I have tried already to follow different post (R: Plot grouped coordinates on world map ; Plotting coordinates of multiple points at google map in R) but I am not having much success with my data.
I am trying to achieve a flat map of the world with my gps coordinate as colored dots (each area a specific color):
area lat long
Agullhas -38,31 40,96
Polar -57,59 76,51
Tasmanian -39,47 108,93
library(RgoogleMaps)
lat <- c(-38.31, -35.50) #define our map's ylim
lon <- c(40.96,37.50) #define our map's xlim
center = c(mean(lat), mean(lon)) #tell what point to center on
zoom <- 2 #zoom: 1 = furthest out (entire globe), larger numbers = closer in
terrmap <- GetMap(center=center, zoom=zoom, maptype= "satallite", destfile = "satallite.png")
problem that now I don't know how to add my points and I will like one color for each region.
Could anyone help me going forward with it?
the other option I have tried is :
library(maps)
library(mapdata)
library(maptools)
map(database= "world", ylim=c(-38.31, -35.5), xlim=c(40.96, 37.5), col="grey80", fill=TRUE, projection="gilbert", orientation= c(90,0,225))
lon <- c(-38.31, -35.5) #fake longitude vector
lat <- c(40.96, 37.5) #fake latitude vector
coord <- mapproject(lon, lat, proj="gilbert", orientation=c(90, 0, 225)) #convert points to projected lat/long
points(coord, pch=20, cex=1.2, col="red") #plot converted points
but the coordinates ends in a wrong position and I am not sure why
Hope someone can help
解决方案 As an alternative to RgoogleMaps
, you can also use the combination ggplot2
with ggmap
.
With this code:
# loading the required packages
library(ggplot2)
library(ggmap)
# creating a sample data.frame with your lat/lon points
lon <- c(-38.31,-35.5)
lat <- c(40.96, 37.5)
df <- as.data.frame(cbind(lon,lat))
# getting the map
mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), zoom = 4,
maptype = "satellite", scale = 2)
# plotting the map with some points on it
ggmap(mapgilbert) +
geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size = 5, shape = 21) +
guides(fill=FALSE, alpha=FALSE, size=FALSE)
you get this result:
这篇关于在地图上绘制坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!