[英]ggmap plotted with bounding coordinates
I am trying to use the solution here for applying a bounding box of coordinates when plotting a ggmap, as specifying get_map() using a bounding box does not work (is converted to center and zoom). 我正在尝试使用此处的解决方案在绘制ggmap时应用坐标的边界框,因为使用边界框指定get_map()无效(转换为中心和缩放)。
However, I end up with a lot of extra gray around my plot. 但是,最终我的绘图周围有很多多余的灰色。 I would like to have a plot fitted nicely where the bounding coordinates are (xmin, xmax, ymin, ymax) = (-170,-30, -60, 110)
我想很好地拟合边界坐标为(xmin,xmax,ymin,ymax)=(-170,-30,-60,110)的图
# Get a Google satellite map of North and South America
map <- get_map(location = c(-100, 20), zoom = 2, maptype = "satellite", source = "google")
ggmap(map)
I would like to have a plot fitted to the coordinates described above. 我想将一个图拟合到上述坐标。
# Attempt to scale the x and y axes
ggmap(map) +
scale_x_continuous(limits = c(-170, -30), expand=c(0,0)) +
scale_y_continuous(limits = c(-60, 110), expand=c(0,0))
What I end up with is a plot that looks like this: 我最终得到的是一个看起来像这样的情节:
Cropped nicely but with excessive gray space at the top. 裁剪效果很好,但顶部有过多的灰色空间。
Edit: I used R 3.3.3 in RStudio 1.0.136, with ggmap 2.7 and ggplot2 2.2.0 编辑:我在RStudio 1.0.136中使用R 3.3.3,以及ggmap 2.7和ggplot2 2.2.0
What you are trying to do exceeds the boundaries of the map. 您试图做的事超出了地图的界限。 The maximum positive/negative
Latitude
on a mercator-style projection is 85.0511... / -85.0511...
, because arctan(sinh(Pi)) * 180 / Pi = 85.0511288
. 墨卡托式投影上的最大正/负
Latitude
为85.0511... / -85.0511...
,因为arctan(sinh(Pi)) * 180 / Pi = 85.0511288
。
This code will yield a correct result: 此代码将产生正确的结果:
ggmap(map, extent = "panel") +
scale_x_continuous(limits = c(-170, -30), expand=c(0,0)) +
scale_y_continuous(limits = c(-60, 85), expand=c(0,0))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.