RGoogleMaps 轴

发布于 2024-11-14 07:30:45 字数 919 浏览 4 评论 0原文

我找不到有关 RGoogleMaps 中轴标签的以下问题的任何文档:

library(RgoogleMaps)
datas <- structure(list(LAT = c(37.875, 37.925, 37.775, 37.875, 37.875), 
                   LON = c(-122.225, -122.225, -122.075, -122.075, -122.025)), 
                   .Names = c("LAT", "LON"), class = "data.frame", 
                   row.names = c(1L, 2L, 3L, 4L, 5L))
# Get bounding box.
boxt <- qbbox(lat = datas$LAT, lon = datas$LON)
MyMap <- GetMap.bbox(boxt$lonR, boxt$latR, destfile = "Arvin12Map.png", 
maptype = "mobile")
PlotOnStaticMap(MyMap, lat = datas$LAT, lon = datas$LON, 
                axes = TRUE, mar = rep(4, 4))

当我在计算机上运行此问题时,水平轴范围从 300W 到 60E,但之间的刻度不是线性间隔的(300W 、200W、100W、0、100E、160W、60W)。 此外,垂直轴从 300S 线性移动到 300N。似乎无论我为数据提供什么数据,轴总是以这种方式标记。

我的问题是:
1.使用此代码的其他机器上是否也出现此问题?
2. 有谁能解释一下吗?

3.任何人都可以建议一种获得正确轴标签的方法(假设这些标签是“不正确的”,但也许我在某种程度上误解了情节!)?

感谢您抽出时间。

I can't find any documentation of the following problem I'm having with the axis labels in RGoogleMaps:

library(RgoogleMaps)
datas <- structure(list(LAT = c(37.875, 37.925, 37.775, 37.875, 37.875), 
                   LON = c(-122.225, -122.225, -122.075, -122.075, -122.025)), 
                   .Names = c("LAT", "LON"), class = "data.frame", 
                   row.names = c(1L, 2L, 3L, 4L, 5L))
# Get bounding box.
boxt <- qbbox(lat = datas$LAT, lon = datas$LON)
MyMap <- GetMap.bbox(boxt$lonR, boxt$latR, destfile = "Arvin12Map.png", 
maptype = "mobile")
PlotOnStaticMap(MyMap, lat = datas$LAT, lon = datas$LON, 
                axes = TRUE, mar = rep(4, 4))

When I run this on my computer the horizontal axis ranges from 300W to 60E, but the ticks in between aren't linearly spaced (300W, 200W, 100W, 0, 100E, 160W, 60W).
Also, the vertical axis moves linearly from 300S to 300N. It seems that no matter what data I supply for datas, the axes are always labeled this way.

My question is:
1. Does this problem occur on other machines using this code?
2. Does anyone have an explanation for it?
and
3. Can anybody suggest a way to get the correct axes labels (assuming these are "incorrect", but maybe i'm somehow misinterpreting the plot!)?

Thank you for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花海 2024-11-21 07:30:45
  1. 正如@Andrie 所建议的,这似乎是一个错误。当axes = TRUE时,PlotOnStaticMap()调用的degAxis()函数会提取发现的漂亮刻度线的x和y绘图坐标代码>axTicks()。 degAxis() 期望这些坐标位于地图的坐标系中,但 rGoogleMaps 将它们作为像素坐标返回,从中心原点计算。绘图大小为 640 x 640 时,漂亮的刻度线在东西向和南北向上分配为 -300、-200、-100、0,100、200、300。最终得到 300W、200W、100W、0、100E、160W、60W,因为由 degAxis() 调用的 DegreeLabelsEW() 函数假设给定的经度必须落在在[-180, 180]内,任何高于180的经度实际上都在西半球(例如,200E是西半球向东20度,即160W)。不知道为什么它对于无意义的 N、S 和 W 坐标的表现不相似。

  2. 快速解决方法,继续使用 MyMap 对象:

    PlotOnStaticMap(MyMap, lat = 数据$LAT, lon = 数据$LON, 
                    轴 = FALSE,mar = 代表(4.5,4))
    
    # x 轴
    xrange <- MyMap$BBOX$ur[2] - MyMap$BBOX$ll[2]
    xticklength <- xrange / (长度(axTicks(1)) - 1)
    xticklabs <- seq(MyMap$BBOX$ll[2], MyMap$BBOX$ur[2], xticklength)
    xticklabs <- 解析(文本=粘贴(sprintf('%.2f',abs(xticklabs)), 
        ifelse(xticklabs < 0, '*度*W', '*度*E'), sep=''))
    轴(1,at=axTicks(1),xticklabs,cex.axis=0.8)
    
    # y 轴
    yrange <- MyMap$BBOX$ur[1] - MyMap$BBOX$ll[1]
    yticklength <- yrange / (长度(axTicks(2)) - 1)
    yticklabs <- seq(MyMap$BBOX$ll[1], MyMap$BBOX$ur[1], yticklength)
    yticklabs <- 解析(文本=粘贴(sprintf('%.2f',abs(yticklabs)), 
        ifelse(yticklabs < 0, '*度*S', '*度*N'), sep=''))
    轴(2,at=axTicks(2),yticklabs,cex.axis=0.8,las=1)
    
  1. Yes

  2. As @Andrie suggested, this appears to be a bug. When axes = TRUE, the degAxis() function called by PlotOnStaticMap() extracts the x and y plot coordinates of the pretty tickmarks found by axTicks(). degAxis() expects these coords to be in the coordinate system of the map, but rGoogleMaps returns them as pixel coordinates, calculated from a central origin. With a plot size of 640 x 640, the pretty tickmarks are assigned to -300, -200, -100, 0,100, 200, 300 in both E-W and N-S directions. You end up with 300W, 200W, 100W, 0, 100E, 160W, 60W, because the degreeLabelsEW() function called by degAxis() assumes that, given longitudes must fall within [-180, 180], any longitudes higher than 180 are in fact in the western hemisphere (e.g. 200E is 20 degrees eastward into the western hemisphere, i.e. 160W). Not sure why it doesn't perform similarly with nonsensical N, S and W coordinates.

  3. A quick workaround, continuing with your MyMap object:

    PlotOnStaticMap(MyMap, lat = datas$LAT, lon = datas$LON, 
                    axes = FALSE, mar = rep(4.5, 4))
    
    # x-axis
    xrange <- MyMap$BBOX$ur[2] - MyMap$BBOX$ll[2]
    xticklength <- xrange / (length(axTicks(1)) - 1)
    xticklabs <- seq(MyMap$BBOX$ll[2], MyMap$BBOX$ur[2], xticklength)
    xticklabs <- parse(text = paste(sprintf('%.2f', abs(xticklabs)), 
        ifelse(xticklabs < 0, '*degree*W', '*degree*E'), sep=''))
    axis(1, at=axTicks(1), xticklabs, cex.axis=0.8)
    
    # y-axis
    yrange <- MyMap$BBOX$ur[1] - MyMap$BBOX$ll[1]
    yticklength <- yrange / (length(axTicks(2)) - 1)
    yticklabs <- seq(MyMap$BBOX$ll[1], MyMap$BBOX$ur[1], yticklength)
    yticklabs <- parse(text = paste(sprintf('%.2f', abs(yticklabs)), 
        ifelse(yticklabs < 0, '*degree*S', '*degree*N'), sep=''))
    axis(2, at=axTicks(2), yticklabs, cex.axis=0.8, las=1)
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文