- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 ggplot2 在 map 上绘制比例尺和指北针的任何解决方案
library(mapdata); library(ggplot2);
nl.map=data.frame(map('worldHires', 'Netherlands')[c('x', 'y')])
ggplot(nl.map, aes(x, y))+geom_path()
最佳答案
几年前,我编写了一些可以绘制比例尺的代码(另请参阅 this post on r-sig-geo ),这是我当时编写的代码。你可以试一试:
首先是一些支持功能:
makeNiceNumber = function(num, num.pretty = 1) {
# Rounding provided by code from Maarten Plieger
return((round(num/10^(round(log10(num))-1))*(10^(round(log10(num))-1))))
}
createBoxPolygon = function(llcorner, width, height) {
relativeCoords = data.frame(c(0, 0, width, width, 0), c(0, height, height, 0, 0))
names(relativeCoords) = names(llcorner)
return(t(apply(relativeCoords, 1, function(x) llcorner + x)))
}
addScaleBar = function(ggplot_obj, spatial_obj, attribute, addParams =
list()) {
addParamsDefaults = list(noBins = 5, xname = "x", yname = "y", unit = "m",
placement = "bottomright", sbLengthPct = 0.3, sbHeightvsWidth = 1/14)
addParams = modifyList(addParamsDefaults, addParams)
range_x = max(spatial_obj[[addParams[["xname"]]]]) - min(spatial_obj[[addParams[["xname"]]]])
range_y = max(spatial_obj[[addParams[["yname"]]]]) - min(spatial_obj[[addParams[["yname"]]]])
lengthScalebar = addParams[["sbLengthPct"]] * range_x
## OPTION: use pretty() instead
widthBin = makeNiceNumber(lengthScalebar / addParams[["noBins"]])
heightBin = lengthScalebar * addParams[["sbHeightvsWidth"]]
lowerLeftCornerScaleBar = c(x = max(spatial_obj[[addParams[["xname"]]]]) - (widthBin * addParams[["noBins"]]), y = min(spatial_obj[[addParams[["yname"]]]]))
scaleBarPolygon = do.call("rbind", lapply(0:(addParams[["noBins"]] - 1), function(n) {
dum = data.frame(createBoxPolygon(lowerLeftCornerScaleBar + c((n * widthBin), 0), widthBin, heightBin))
if(!(n + 1) %% 2 == 0) dum$cat = "odd" else dum$cat = "even"
return(dum)
}))
scaleBarPolygon[[attribute]] = min(spatial_obj[[attribute]])
textScaleBar = data.frame(x = lowerLeftCornerScaleBar[[addParams[["xname"]]]] + (c(0:(addParams[["noBins"]])) * widthBin), y = lowerLeftCornerScaleBar[[addParams[["yname"]]]],
label = as.character(0:(addParams[["noBins"]]) * widthBin))
textScaleBar[[attribute]] = min(spatial_obj[[attribute]])
return(ggplot_obj +
geom_polygon(data = subset(scaleBarPolygon, cat == "odd"), fill = "black", color = "black", legend = FALSE) +
geom_polygon(data = subset(scaleBarPolygon, cat == "even"), fill = "white", color = "black", legend = FALSE) +
geom_text(aes(label = label), color = "black", size = 6, data = textScaleBar, hjust = 0.5, vjust = 1.2, legend = FALSE))
}
library(ggplot2)
library(sp)
data(meuse)
data(meuse.grid)
ggobj = ggplot(aes(x = x, y = y, color = zinc), data = meuse) + geom_point()
# Make sure to increase the graphic device a bit
addScaleBar(ggobj, meuse, "zinc", addParams = list(noBins = 5))
关于r - map-ggplot2 上的比例尺和指北针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15486551/
我已经开始尝试在 Canvas 对象上绘图。在过去,我对 Canvas 的接触一直以图像处理为中心 (NPI),因此我对它的坐标系和转换过程比较熟悉。我正在使用屏幕尺寸为 30 X 30 的测试 Ca
当 size 不是原生时,我希望有一个内联 svg 元素的内容缩放。当然,我可以将它作为一个单独的文件并像这样缩放它。 index.html: foo.svg: 但是,我想通过 CSS 向 SVG
我想知道如何在leafleat.js 中显示比例尺 map 。那就是:我想要这个 而不是这个 (带到 leaflet tutorial )。请参见图片的左下角。 最佳答案 您可以使用 L.contro
我遇到了一个问题,我相信很多 iOS 开发者以前都遇到过,所以我来这里寻求帮助。我在一家公司工作,我正在开发的 iPhone 应用程序的设计规范是在 Adobe PhotoShop 中制定的。我得
谷歌地图应用程序默认显示标尺/比例尺,当我们放大/缩小 map 时会出现。我想在我正在构建的 android 应用程序中显示一个类似的标尺。我正在使用 Google Map V2,但似乎没有任何可用的
我有一个从 0 到 275 的 UISlider。我想使用 slider 来缩放 UIImageView。 当我的 slider 值为 0 时,我的 UIImageView 应该具有原始大小(scal
使用 GeoTools 我能够使用 JMapPane 类显示一个简单的形状文件。我的要求是绘制一个类似于任何 map 的条形图,在我放大/缩小时显示 map 的比例尺(以米为单位)与条形图的长度相关。
在我的 Java 应用程序中,我使用 JmapViewer; map 绘制在 jPanel 上。是否可以获取当前缩放级别对应的 map 比例尺?该 map 基于著名的墨卡托投影: X = R * lo
我有一个托管 Google 地球插件实例的应用程序,我有兴趣获取 map 的当前比例并在我的应用程序中使用它。 我知道我可以使用 GEOptions 并设置比例图例可见性,但我想在我的应用程序中使用实
我的缩放级别为 3-21。分别缩小-放大。 但我想用给定的屏幕条(屏幕宽度?)来计算缩放级别到米/公里距离,就像 Gmaps 比例尺一样。 示例: 缩放级别 20 = 数百米 缩放级别 3 = 数千公
我正在努力添加一个 map 比例,该比例根据当前缩放级别在屏幕上显示当前长度。我有一种感觉,它可能存在一些预定义的类来使用,但我不知道......?我到处搜索但找不到任何东西。 我非常感谢任何帮助 =
我正在使用 Google API v2 map Android,但我无法在其上显示比例尺。请帮帮我,我能做些什么来在我的 map 上显示比例尺吗?我正在寻找它,但没有帮助。 最佳答案 Google 在
我正在寻求有关创建用于 D3.js 可缩放 map 的 map 比例尺的帮助。我经常使用 D3.js 为我的工作创建 map 。我从来没有在过去构建的 map 上放置比例尺,但最近我收到了在 map
我是一名优秀的程序员,十分优秀!