所描述的问题涉及表示多维缩放(MDS)坐标以及真实数据点(城市的经度和纬度)。
所以,我有一个距离矩阵,上传到这里。矩阵中的条目表示九个美国城市之间的距离(以英里为单位)。该矩阵输入到 MDS。MDS 生成一组我希望在地图上绘制的坐标。
让我们先画出美国的地图。(图贴在下面。)
library(ggplot2)
library(maps)
library(ggmap)
# Build dataframe for plotting map of USA
states <- map_data("state")
geo.city <- c("Atlanta", "Boston", "Dallas", "Indianapolis", "Los Angeles", "Memphis", "St. Louis", "Spokane", "Tempa")
geo.codes <- geocode(geo.city)
geo.data <- data.frame(name = geo.city, long = geo.codes[, 1], lat = geo.codes[, 2])
# Plot map
ggplot(mapstates, aes(long, lat, group = group)) +
geom_polygon(fill = I("grey85")) +
geom_path(color = "gray") +
coord_map(project="globular") +
xlab("Longitude") + ylab("Latitude") +
annotate("point", x = geo.data$long, y = geo.data$lat) +
#annotate("point", x = fit$points[,1], y = fit$points[, 2]) +
annotate("text", x = geo.data$long, y = geo.data$lat + 0.7, label = geo.data$name, size = 3) +
theme_bw()
现在是 MDS 部分:
my.data <- read.table(file = "https://dl.dropboxusercontent.com/u/540963/airline_distances.csv", header = TRUE, sep = ",", row.names = 1)
my.mat <- as.matrix(my.data)
D <- dist(my.mat)
fit <- cmdscale(d = D, k = 2)
拟合的坐标存储在fit$points
对象中:
> fit$points
[,1] [,2]
Atlanta -1563.1298 -89.67381
Boston -780.5404 2208.74325
Dallas -202.2759 -1053.70443
Indianapolis -1198.6748 -181.96331
Los Angeles 3445.3295 -412.50061
Memphis -1171.9280 -793.69762
St. Louis -1018.1581 -622.13715
Spokane 3712.7007 438.84657
Tampa -1223.3233 506.08712
我的问题:如何缩放这些点以将它们添加到我的地图中。任何指针将不胜感激。