繁体   English   中英

在地图上绘制点

[英]Plotting points on a map

我试图在地图上绘制坐标点,但出现plot.new错误。 能否请你帮忙?

library(maptools)
library(ggmap)
library(mapproj)    
table <- read.table("table.txt", header=TRUE, sep=",")
map <- get_map(location = 'France', zoom = 6, maptype = c("toner"))
points(table$LONG, table$LAT, pch=21, bg=color, cex=0.7, lwd=.4)
ggmap(map)

这是一个表格的概念:

CITY,LAT,LONG
Paris,48.856667,2.351944
Lyon,45.766944,4.834167
Bordeaux,44.838611,0.578334

试试geom_point

library(maptools)
library(ggmap)
library(mapproj)

city <- c("Paris", "Lyon", "Bordeaux")
my.lat <- c(48.856667, 45.766944, 44.838611)
my.long <- c(2.351944, 4.834167, 0.578334)

points <- data.frame(lon=my.long, lat=my.lat)

map <- get_map(location = c(left = -5, bottom = 42, right=9, top = 51 ), source = 'stamen', maptype = 'toner')
france <- ggmap(map, extent = 'normal')
france + geom_point(data=points, col="red")

在此处输入图片说明

尝试使用命令?ggmap可获得大量示例。 我认为该手册做得很好,因为在阅读您的问题之前,我什至都不知道这些功能。 谢谢! 我学到新东西了。

在尝试跑步之前,先学会走路。

points功能将点添加到现有图形。 您还没有现有的图形(除非您已经做过一些未向我们展示的图形)。

因此,如果您在开始绘制之前进行points运算,将会得到一个错误。 例如:

points(1:10,1:10) # plot.new error
plot(1:10,1:10) # no error, starts a new plot
points(10:1,1:10) # adds extra points, no error.

ggplot所有内容ggplot相关。 另外,这与统计无关,因此您应该发布到StackOverflow。 我已经标记了它,它可能会迁移...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM