簡體   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