- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我认为我有一个非常简单的问题,但我无法在任何地方找到答案。
我有很多包含龙虾捕获量的数据。一切看起来都很像这样。
Trip.ID Latitude Longitude DateTime ML6 TotalNephropsLandings
16409 OTB_CRU_32-69_0_0DK102831 57.931 9.277 2012-10-04 19:02:00 OTB_CRU_32-69_0_0 0.2188619
16410 OTB_CRU_32-69_0_0DK102831 57.959 9.375 2012-10-04 21:02:00 OTB_CRU_32-69_0_0 0.2188619
16411 OTB_CRU_32-69_0_0DK102831 58.201 10.232 2012-10-04 02:00:00 OTB_CRU_32-69_0_0 0.2188619
16412 OTB_CRU_32-69_0_0DK102831 58.208 10.260 2012-10-04 03:00:00 OTB_CRU_32-69_0_0 0.2188619
16413 OTB_CRU_32-69_0_0DK102831 58.169 10.078 2012-10-03 23:00:00 OTB_CRU_32-69_0_0 0.2188619
16414 OTB_CRU_32-69_0_0DK102831 57.919 9.227 2012-10-04 18:00:00 OTB_CRU_32-69_0_0 0.2188619
我想做的只是根据“ML6”列制作一张包含区域周围轮廓的 map ,这是用于钓鱼的不同工具。
我尝试使用 geom_densis2d,它看起来像这样: 然而我真的不想展示密度,只想展示它们存在的地方。因此,基本上一条线围绕一组坐标,这些坐标来自 ML6 中的同一级别。有人能帮我解决这个问题吗?
如果有替代方案将它们也填充为多边形,那就太好了。但也许可以使用“fill=”简单地完成。
如果有人知道如何在没有 R 的情况下做到这一点,也欢迎您提供帮助,但那样我可能需要更深入的信息。
很抱歉没有生成更多的数据框...
当然,我应该生成我的情节代码,所以这里基本上是:
#Get map
map <- get_map(location=c(left= 0, bottom=45, right=15 ,top=70), maptype = 'satellite')
ggmap(map, extent="normal") +
geom_density2d(data = df, aes(x=Longitude, y=Latitude, group=ML6, colour=ML6))
最佳答案
可能有更好的方法来完成这项工作。但是,这是我为您提供的方法。我希望这种方法适用于 ggmap
以及。鉴于我有时间,这是我对你最好的。由于您的样本数据太小,我决定使用我自己的部分数据。您要做的就是查看ggplot_build(objectname)$data[1]
。 (看起来,当您使用 ggmap
时,数据将在 ggplot_build(object name)$data[4]
中。)例如,创建一个像这样的对象。
foo <- ggmap(map, extent="normal") +
geom_density2d(data = df, aes(x=Longitude, y=Latitude, group=ML6, colour=ML6))
然后,输入 ggplot_build(foo)$data[1]
。您应该看到一个数据框 ggplot
正在使用。将有一个名为 level
的列。具有最小级别值的数据子集。我正在使用filter
来自dplyr
。例如,
foo2 <- ggplot_build(foo)$data[1]
foo3 <- filter(foo2, level == 0.02)
foo3 现在有数据点,允许您在 map 上画线。该数据包含关卡最外圈的数据点。你会看到类似这样的东西。
# fill level x y piece group PANEL
#1 #3287BD 0.02 168.3333 -45.22235 1 1-001 1
#2 #3287BD 0.02 168.3149 -45.09596 1 1-001 1
#3 #3287BD 0.02 168.3197 -44.95455 1 1-001 1
然后,您将执行如下操作。就我而言,我没有谷歌地图。我有新西兰的 map 数据。所以我用第一个 geom_path
画这个国家。第二个geom_path
就是你需要的。确保将 lon 和 lat 更改为 x 和 y,如下所示。这样我认为您就拥有了想要的圆圈。
# Map data from gadm.org
NZmap <- readOGR(dsn=".",layer="NZL_adm2")
map.df <- fortify(NZmap)
ggplot(NULL)+
geom_path(data = map.df,aes(x = long, y = lat, group=group), colour="grey50") +
geom_path(data = foo3, aes(x = x, y = y,group = group), colour="red")
更新
这是另一种方法。在这里我使用了我的答案 this post 。您基本上可以确定数据点来绘制圆(多边形)。我在帖子里有一些链接。请看一看。您可以了解循环中发生了什么。抱歉很短。但是,我认为这种方法可以让你画出你想要的所有圆圈。请记住,结果可能不是像轮廓那样光滑的圆圈。
library(ggmap)
library(sp)
library(rgdal)
library(data.table)
library(plyr)
library(dplyr)
### This is also from my old answer.
### Set a range
lat <- c(44.49,44.5)
lon <- c(11.33,11.36)
### Get a map
map <- get_map(location = c(lon = mean(lon), lat = mean(lat)), zoom = 14,
maptype = "satellite", source = "google")
### Create pseudo data.
foo <- data.frame(x = runif(50, 11.345, 11.357),
y= runif(50, 44.4924, 44.4978),
group = "one",
stringsAsFactors = FALSE)
foo2 <- data.frame(x = runif(50, 11.331, 11.338),
y= runif(50, 44.4924, 44.4978),
group = "two",
stringsAsFactors = FALSE)
new <- rbind(foo,foo2)
### Loop through and create data points to draw a polygon for each group.
cats <- list()
for(i in unique(new$group)){
foo <- new %>%
filter(group == i) %>%
select(x, y)
ch <- chull(foo)
coords <- foo[c(ch, ch[1]), ]
sp_poly <- SpatialPolygons(list(Polygons(list(Polygon(coords)), ID=1)))
bob <- fortify(sp_poly)
bob$area <- i
cats[[i]] <- bob
}
cathy <- as.data.frame(rbindlist(cats))
ggmap(map) +
geom_path(data = cathy, aes(x = long, y = lat, group = area), colour="red") +
scale_x_continuous(limits = c(11.33, 11.36), expand = c(0, 0)) +
scale_y_continuous(limits = c(44.49, 44.5), expand = c(0, 0))
关于r - 使用 ggmap/ggplot2 在 map 上按组绘制等高线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26842278/
当我尝试将 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
我是一名优秀的程序员,十分优秀!