- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 ggmap 上绘制路线和点,我需要添加一个图例来列出点代表的名称
IE。
1 比尔哈里斯,
2 安妮·琼斯
等等..
我已经准备好了样本数据。
structure(list(business.names = structure(c(8L, 9L, 5L, 6L, 7L,
1L, 4L, 3L, 2L, 10L), .Label = c("Bill Harris", "Anne Jones",
"Sue Perkins", "Morris Jones", "Bert Harris", "Bob Jones",
"Mike Taylor", "Paul Jones", "John Roberts",
"Fred Morris"), class = "factor"), X1 = structure(c(7L,
8L, 10L, 9L, 3L, 2L, 1L, 4L, 5L, 6L), .Label = c("53.186744",
"53.1884117", "53.1894004", "53.189836", "53.1902965", "53.1905138631287",
"53.1912196", "53.1916771", "53.193418", "53.1934748"), class = "factor"),
X2 = structure(c(7L, 3L, 2L, 1L, 5L, 4L, 6L, 10L, 9L, 8L), .Label = c("-2.881248",
"-2.8814698", "-2.8846099", "-2.88802", "-2.8886692", "-2.890165",
"-2.8902453", "-2.89043889005541", "-2.8919373", "-2.893896"
), class = "factor")), .Names = c("business.names", "X1",
"X2"), row.names = c(10L, 9L, 8L, 1L, 7L, 6L, 3L, 4L, 5L, 2L), class = "data.frame")
create.map<-function(lst){
require("ggmap")
require("qmap")
way.points<-data.frame(lapply(lst[,1:3], as.character), stringsAsFactors=FALSE)
rte.from <- apply(way.points[-nrow(way.points),2:3],1,paste,collapse=",")
rte.to <- apply(way.points[-1,2:3],1,paste,collapse=",")
rte <- do.call(rbind,
mapply(route, rte.from, rte.to, SIMPLIFY=FALSE,
MoreArgs=list(mode="walking",structure="legs")))
map.centre<-c(mean(as.numeric(way.points$X2)),mean(as.numeric(way.points$X1)))
coords <- rbind(as.matrix(rte[,7:8]),as.matrix(rte[nrow(rte),9:10]))
coords <- as.data.frame(coords)
ggm <- qmap(location=map.centre,zoom = 15, maptype = "road", legend="topright")
ggm +
geom_path(data=coords,aes(x=startLon,y=startLat),color="blue",size=2)+
geom_point(data=way.points,aes(x=as.numeric(X2),y=as.numeric(X1)),
size=10,color="yellow")+
geom_text(data=way.points,
aes(x=as.numeric(X2),y=as.numeric(X1), label=seq_along(X1)))
}
最佳答案
这是一种可能性。您可能想要安排企业名称并使用 geom_point
再一次创造传奇。在此 geom_point
,您使用 alpha = 0
.因此,您实际上看不到任何点;您只看到第一个 geom_point
中指定的黄点.在这里,您的数据被称为 mydf
.
foo <- mutate(mydf, business.names = paste(seq_along(X1), business.names, sep = " "))
# business.names X1 X2
#1 1 Paul Jones 53.1912196 -2.8902453
#2 2 John Roberts 53.1916771 -2.8846099
#3 3 Bert Harris 53.1934748 -2.8814698
#4 4 Bob Jones 53.193418 -2.881248
#5 5 Mike Taylor 53.1894004 -2.8886692
#6 6 Bill Harris 53.1884117 -2.88802
#7 7 Morris Jones 53.186744 -2.890165
#8 8 Sue Perkins 53.189836 -2.893896
#9 9 Anne Jones 53.1902965 -2.8919373
#10 10 Fred Morris 53.1905138631287 -2.89043889005541
create.map<-function(lst){
require("ggmap")
require("qmap")
way.points <-data.frame(lapply(lst[,1:3], as.character), stringsAsFactors=FALSE)
rte.from <- apply(way.points[-nrow(way.points),2:3],1,paste,collapse=",")
rte.to <- apply(way.points[-1,2:3],1,paste,collapse=",")
rte <- do.call(rbind,
mapply(route, rte.from, rte.to, SIMPLIFY=FALSE,
MoreArgs=list(mode="walking",structure="legs")))
map.centre<-c(mean(as.numeric(way.points$X2)),mean(as.numeric(way.points$X1)))
coords <- rbind(as.matrix(rte[,7:8]),as.matrix(rte[nrow(rte),9:10]))
coords <- as.data.frame(coords)
ggm <- qmap(location=map.centre,zoom = 15, maptype = "road", legend="topright")
ggm +
geom_path(data=coords,aes(x=startLon,y=startLat),color="blue",size=2)+
geom_point(data=way.points,aes(x=as.numeric(X2),y=as.numeric(X1)),
size=10,color="yellow")+
geom_point(data=way.points,aes(x=as.numeric(X2),y=as.numeric(X1),
color = factor(business.names, levels=business.names)), alpha = 0) +
geom_text(data=way.points,
aes(x=as.numeric(X2),y=as.numeric(X1), label=seq_along(X1))) +
scale_color_discrete(name = "Business names") +
theme(legend.key = element_rect(fill = NA))
}
create.map(foo)
关于r - 将图例/文本表添加到具有多个图层的 ggmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27730124/
当我尝试将 ggmap 与形状文件结合时,我遇到了剪切问题。 Kahle 和 Wickham (2013: 158) 中的示例工作正常,因为来自 ggmap 的光栅图像覆盖了整个形状文件。下面是当我尝
我正在尝试解决以下问题。 我使用 ggplot2 绘制岛屿 map : island = get_map(location = c(lon = -63.247593, lat = 17.631598)
我正在生成一些 map ,我想在 ggmap 上显示县的边界路线图。这是使用德克萨斯州部分地区的示例。 library(ggmap) map = get_map(location = c(-95.31
我有一个城市和相关信息的列表,我已经放在一个数据框中,如下所示: library(plyr) library(dplyr) library(ggmap) library(Imap) cities <-
我试图用 ggmap 在北极绘制一个特定区域.该地区的中心在纬度附近。 80 长。 0,不幸的是只显示灰色背景和经纬度轴。我试图绘制不同的区域,我的代码似乎适用于每个位置,除了纬度以外的区域。 73.
我正在使用一个空间数据集(主要是一个城市区域上的多边形),并且我想根据不同的缩放级别来产生不同的 View 。 当绘图边界框大于包含多边形的区域时,一切都很好。但是在放大时,某些多边形会得到边界框之外
我正在尝试使用 ggmap 在 map 上绘制点,但我不知道如何从 map 背景中删除国家名称 library(ggmap) library(mapproj) map tbl plot<-ggmap
我正在使用 ggmap,希望有一张以澳大利亚为中心的世界地图,我可以轻松地绘制地理编码点。与其他一些 map 包相比,ggmap 似乎更容易使用。然而,当我使用下面的代码浏览 map 时,它会出错。
我最近遇到了 ggmap 函数的问题 - 从来没有遇到过。 我有这个data.frame: > head(df) longitude latitude freq 1 -118.7093 34.13
我在 ggmap 包中使用了 Stamen 背景 map 。我想用 "#C0C0C0" 替换光栅背景图像中的所有黑色元素(即颜色 "#000000" - 基本上看起来更像 toner light 背景
我想用 R 和 ggmap 包可视化一个数据框。 df: | lon | lat | |-----------|-----------| | 6.585863 | 51.09
我正在使用 ggmap 来查找位置。某些位置会产生错误。例如, library(ggmap) loc = 'Blue Grass Airport' geocode(loc, output = c("m
我想知道是否有人使用 ggmap 围绕纬度/经度点绘制圆半径?例如,我想绘制一个给定的点,然后在该点周围 2,500 英尺的半径范围内绘制和着色。我脑子里有一个关于如何使用更大的圆周公式来做到这一点的
是否可以将 ggmap 保存到本地文件? 上下文:我需要一个大区域的高分辨率 map ,它需要 stamen服务器好久才搞定。我认为最好先获取 map ,然后将其保存到文件中,然后再处理本地副本。 我
我正在 ggmap 上绘制路线和点,我需要添加一个图例来列出点代表的名称 IE。 1 比尔哈里斯, 2 安妮·琼斯 等等.. 我已经准备好了样本数据。 structure(list(business.
一张图片胜过千言万语: 观察到的行为:从上图可以看出,国家名称与其实际几何形状不匹配。 预期行为:我想正确地将数据框与其几何图形连接起来,并在 ggmap 中显示结果。 我以前加入过不同的数据框,但显
我正在尝试绘制一些显示完整人口的信息,然后按 map 上的位置绘制该人口的子集。我见过使用同心圆或 3-d 倒锥体来表达这一点的数据可视化。我就是不知道怎么做 ggplot/ggmap 这是 Pain
我想在谷歌的灰色 map 上绘制各个城市的数据点。由于这些城市彼此之间有一些距离,我想我会使用多面图。 创建 map 很容易;请参阅下面的图像和代码。但是,每个方面都显示相同的区域 - 在本例中为大伦
我有以下代码。 library(ggmap) x = geocode("641123",output='all') x$results[[1]]$geometry$location$lat 显示 55
我想在 ggmap 上绘制热图。 library(ggmap) turku<-get_map('turku', zoom=13) turkumap<-ggmap(turku, extent
我是一名优秀的程序员,十分优秀!