繁体   English   中英

geom_polygon填充中的纹理

[英]texture in geom_polygon fill

我需要创建一个欧洲地图来显示变量在各个国家之间的分布。 我需要黑白地图。 我依靠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))

第一个geom_polygon用于背景,我假设我必须在此处编辑fill 显然,这对于区分无信息与变量I的低值很重要。 考虑到我必须依靠黑白,我想到了使用纹理的想法,但是我愿意接受其他建议。

谢谢!

使用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))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM