R图绘制经度和​​纬度点

时间:2012-04-05 15:57:05

标签: r maps latitude-longitude

我有一张美国地图和一张我要绘制的long,lat列表。一旦我开始工作,我也想切换到“世界”地图。生成地图,但地图上不显示任何点。 TSV文件的第一行包含此标题:

LONG{tab}LAT
R似乎正在“流量”表中读取确定。我做错了什么?

library("maps")

traffic = read.table("C:/temp/traffic_10.40.tsv", header=T, sep="\t")
png(filename="C:/temp/usa.png", width=850, height=600, bg="white")
map('state', plot = TRUE, fill = FALSE, col = palette())
title("Destinations")
points(x=traffic$LONG,y=traffic$LAT,col='red',cex=0.75)
dev.off()

修改

> dput(traffic)
structure(list(LONG = c(47.6218, 32.7942, 34.1121, 40.0068, 47.6218,
33.9553, 33.7629, 40.0068, 39.05, 38.1075, 33.7629, 32.769, 37.3857,
29.4576, 34.1674, 38.8147, 32.7942, 31.1429, 40.3254, 30.3059,
38.2248, 47.6218, 33.9553, 38.1075, 27.1943, 29.4576, 30.5175,
38.5668, 42.6657, 40.2982, 32.7539, 40.6698, 47.6742, 32.7942,
47.6218, 35.8219), LAT = c(-122.35, -96.7653, -118.411, -75.1347,
-122.35, -83.3937, -84.4226, -75.1347, -77.4833, -122.264, -84.4226,
-96.5998, -122.026, -98.5054, -84.8014, -77.0647, -96.7653, -81.471,
-78.9195, -97.7505, -85.7412, -122.35, -83.3937, -122.264, -80.2432,
-98.5054, -97.6721, -121.467, -73.799, -111.698, -97.3363, -73.9438,
-122.115, -96.7653, -122.35, -78.6588)), .Names = c("LONG", "LAT"
), class = "data.frame", row.names = c(NA, -36L))

另外,我是R新手,并试图在谷歌上找到这个,但成功有限,因为我不确定该搜索到底是什么。

3 个答案:

答案 0 :(得分:8)

问题在于您的数据集而不是您以后的代码。

第一点有一个坐标47.6218,另一个-122.35Latitudes不能超出[-90,90]度范围,因此longitude必须为-122.35,纬度为47.6218,与您的数据集相反。 This is slightly north of the Seattle Space needle

x(水平)传统上是经度或东经; y(垂直)传统上是纬度或北极

答案 1 :(得分:1)

一种选择是使用googleVis。你可以用Google-Maps风格绘制你的积分。

答案 2 :(得分:1)

固定。我交换了$ LAT和$ LONG。现在它完美无缺。

points(x=traffic$LAT,y=traffic$LONG,col='red',cex=0.75)