【发布时间】:2017-10-28 18:13:38
【问题描述】:
我需要创建一张欧洲地图来显示变量在不同国家/地区的分布。我需要黑白地图。我依靠ggplot 并以approach 为例。我根据this blogpost更改了图例。所有这些都适用于这个结果:
我的问题是如何更改地图,以使我缺少填充信息并显示为纯白色的国家/地区具有纹理(我正在考虑对角线)?
由于我的脚本有点乱,这里只展示ggplot,没有数据准备部分:
require(ggplot2)
plotCoords <- read.csv("http://eborbath.github.io/stackoverflow/PlotCoords.csv")
showCoords <- read.csv("http://eborbath.github.io/stackoverflow/showCoords.csv")
ggplot() +
geom_polygon(
data = plotCoords,
aes(x = long, y = lat, group = group),
fill = "white", colour = "darkgrey", size = 0.6) +
geom_polygon(
data = showCoords,
aes(x = long, y = lat, group = group),
fill = "grey", colour = "black", size = 0.6) +
geom_polygon(
data = showCoords,
aes(x = long, y = lat, group = group, fill = sh_left),
colour = "black", size = 0.1) +
scale_fill_gradient(
low = "gray90", high = "gray0",
name = "Share of left-wing protesters",
guide = guide_colorbar(
direction = "horizontal",
barheight = unit(2, units = "mm"),
barwidth = unit(50, units = "mm"),
draw.ulim = F,
title.position = 'top',
title.hjust = 0.5,
label.hjust = 0.5
)) +
scale_x_continuous(element_blank(), breaks = NULL) +
scale_y_continuous(element_blank(), breaks = NULL) +
coord_map(xlim = c(-26, 47), ylim = c(32.5, 73)) +
theme_bw() +
theme(legend.justification = c(-0.4, 1.2), legend.position = c(0, 1))
第一个geom_polygon 用于背景,我想我必须在那里编辑fill。显然,这对于将没有信息与我绘制的变量的低值区分开来很重要。鉴于我必须依赖黑白,我想出了使用纹理的想法,但我愿意接受其他建议。
谢谢!
【问题讨论】:
-
我担心
ggplot2可能无法使用纹理,遵循 Hadley 对 this related question 的回答。不过那已经很老了,所以也许现在已经实现了! -
尽管如此,我认为您并不真正需要纹理来分隔没有数据的国家/地区。它们已经是带有灰色边框的纯白色,与变量值较低的国家/地区的浅灰色和黑色边框形成鲜明对比。情节看起来不错!
标签: r ggplot2 data-visualization