gpt4 book ai didi

r - geom_polygon 填充中的纹理

转载 作者:行者123 更新时间:2023-12-02 07:20:41 25 4
gpt4 key购买 nike

我需要创建一张欧洲 map 来显示某个变量在各个国家/地区的分布情况。我需要黑白 map 。我依靠 ggplot 并遵循了这个 approach举个例子。我根据 this blogpost 更改了图例.所有这一切都适用于这个结果:enter image description here

我的问题是如何更改 map ,使我缺少填充信息并显示为纯白色的国家/地区上面有纹理(我想是对角线)?

由于我的脚本有点乱,这里只展示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 绘图的低值很重要。考虑到我必须依赖黑白,我想到了使用纹理的想法,但我愿意接受其他建议。

谢谢!

最佳答案

technically possible with gridSVG ,但不确定是否值得付出努力。

enter image description here

我在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))

关于r - geom_polygon 填充中的纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46992932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com