geom_polygon填充中的纹理

ebo*_*ath 2 r data-visualization ggplot2

我需要创建一张欧洲地图,以显示各国之间变量的分布情况.我需要黑白地图.我依靠ggplot并遵循这种方法作为例子.我根据这篇博文改变了传奇.所有这一切都适用于此结果:在此输入图像描述

我的问题是如何改变地图的方式,我错过了填充信息的国家和显示为纯白色的国家有一个纹理覆盖他们(我在想对角线)?

由于我的脚本有点乱,我只是在这里显示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))
Run Code Online (Sandbox Code Playgroud)

第一个geom_polygon是背景,我假设我必须在fill那里编辑.显然,这对于区分变量I图的低值没有信息很重要.鉴于我必须依赖黑白,我提出了使用纹理的想法,但我愿意接受其他建议.

谢谢!

bap*_*ste 6

使用gridSVG技术上是可行的,但不确定它是否值得付出努力.

在此输入图像描述

我创建了一个基于GeomPolygon的新geom,并修改了draw_panel方法返回,

gl <- by(munched, munched$group, 
         function(m){
           g <- polygonGrob(m$x, m$y, default.units = "native")

           patternFillGrob(g, 
                           pattern = pattern(linesGrob(gp=gpar(col="red",lwd=3)),
                                             width = unit(2, "mm"), height = unit(2, "mm"),
                                             dev.width = 1, dev.height = 1))
         }, simplify = FALSE)

gTree(children = do.call(gList, gl))
Run Code Online (Sandbox Code Playgroud)