GGR多层次地图图例/指南问题

GGR多层次地图图例/指南问题,r,ggplot2,legend,ggmap,R,Ggplot2,Legend,Ggmap,作为学习R的一个项目,我一直在尝试从英国各地的邮政编码创建会员位置地图。我几乎达到了我想要的结果,但事实证明,解决这些问题非常令人沮丧。这张图片是我目前最大的努力: 我仍然想改变: 去掉无关的图例0.16、0.5正方形,它们是从尺寸arg到几何点的。如果删除尺寸=0.16 arg,则指南/图例将消失,但几何尺寸也将返回默认值。这种情况也发生在黑色指南上——显然来自于一种颜色——但为什么呢 正确剪裁stat_density2d多边形,这些多边形在剪裁时表现出不期望的行为请参见顶部附近的右下角绘图

作为学习R的一个项目,我一直在尝试从英国各地的邮政编码创建会员位置地图。我几乎达到了我想要的结果,但事实证明,解决这些问题非常令人沮丧。这张图片是我目前最大的努力:

我仍然想改变:

去掉无关的图例0.16、0.5正方形,它们是从尺寸arg到几何点的。如果删除尺寸=0.16 arg,则指南/图例将消失,但几何尺寸也将返回默认值。这种情况也发生在黑色指南上——显然来自于一种颜色——但为什么呢

正确剪裁stat_density2d多边形,这些多边形在剪裁时表现出不期望的行为请参见顶部附近的右下角绘图

控制包括县边界的geom_路径的线宽:目前太厚,我希望显示约1/2的厚度,但通过包含“大小”值,我所能实现的就是使线变得非常厚-太厚以至于它们模糊了整个地图

R代码使用revgeocode查找最靠近中心点的地名,但我不知道如何在地图上添加注释。我想把它放在英国地图右上角北海上方的文本框中,可能还有一条指向该点的线/箭头。一个更简单的选择是在英国地图下方,x轴下方的一些文字。。。但我不知道怎么做。在这种情况下,geom_rect/geom_文本似乎令人担忧

最后,我想将地图导出到高分辨率图像,但当我这样做时,一切又会发生变化,请参见:

左侧显示高分辨率~1700x1800px图像,右侧显示Rstudio版本~660x720px图像。地图的比例已经改变,几何图形文本和中心点的几何图形点现在很小。如果两个地图行之间的间隙总是相当小,而不是在高分辨率下很小,我会很高兴

代码

基础知识:阅读成员邮政编码列表,加入mySociety邮政编码表OSGB位置,使用spTransform将位置转换为Lat/long,计算binhex和密度层,使用ggmap绘图

所有这些的代码都有些冗长,因此我将其作为要点上传:

但作为参考,映射代码的“胆量”如下所示:

# Get a stylised base map for the whole-of-uk maps.
map.bbox = c(left = -6.5, bottom = 49.5, right = 2, top = 58)
basemap.uk <- get_stamenmap(bb = map.bbox, zoom=calc_zoom(map.bbox), maptype="watercolor")

# Calculate the density plot - a continuous approximation.
smap.den <- stat_density2d(aes(x = lat, y = lon, fill = ..level.., alpha = ..level..),
               data = membs.wgs84.df, geom = "polygon", 
               breaks=2/(1.5^seq(0,12,by=1)), na.rm = TRUE)

# Create a point on the map representing the centroid, and label it.
cmap.p <- geom_point(aes(x = clat, y = clon), show_guide = FALSE, data = centroid.df, alpha = 1)
cmap.t1 <- geom_text(aes(x = clat, y = clon+0.22, label = "Centre", size=0.16), data = centroid.df)
cmap.t2 <- geom_text(aes(x = clat, y = clon+0.1, label = "Centre", size=0.25), data = centroid.df)

# Create an alternative presentation, as binned hexagons, which is more true to the data.
smap.bin <- geom_hex(aes(x = lat, y = lon),
             data = membs.wgs84.df, binwidth = c(0.15, 0.1), alpha = 0.7, na.rm = TRUE)

# Create a path for the county and country boundaries, to help identify map regions.
bounds <- geom_path(aes(x = long, y = lat, group = group, colour = "black"), show_guide = FALSE,
               data = boundaries.subset, na.rm = TRUE)

# Create the first two actual maps: a whole-uk binned map, and a whole-uk density map.
map.bin <- ggmap(basemap.uk) + smap.bin + grad + cmap.p + cmap.t1
map.den <- ggmap(basemap.uk) + smap.den + alpha + cmap.p + cmap.t1

# Create a zoomed-in map for the south-east, to show greater detail. I would like to use this
# bbox but google maps don't respect it :(
map.lon.bbox = c(left = -1, bottom = 51, right = 1, top = 52)
# Get a google terrain map for the south-east, bbox roughly (-1.7,1.7, 50.1, 53)
basemap.lon <- get_map(location = c(0,51.8), zoom = 8, maptype="terrain", color = "bw")
# Create a new hexbin with more detail than earlier.
smap.lon.bin <- geom_hex(aes(x = lat, y = lon),
             data = membs.wgs84.df, bins=26, alpha = 0.7, na.rm = TRUE)

# Noe create the last two maps: binned and density maps for London and the SE.
lonmap.bin <- ggmap(basemap.lon) + bounds + smap.lon.bin + grad + cmap.p + cmap.t2
lonmap.den <- ggmap(basemap.lon) + bounds + smap.den + alpha + cmap.p + cmap.t2

# Arrange the maps in 2x2 grid, and tell the grid code to let the first row be taller than the second.
multiplot(map.bin, lonmap.bin, map.den, lonmap.den, heights = unit( c(10,7), "null"), cols=2 )

第一点:第三点:在aes之外使用较小的size值,例如size=1。第二点和第四点相当复杂,都值得单独提出。