【发布时间】:2019-09-04 20:50:52
【问题描述】:
当我绘制它时,我正在尝试更改 sf 对象区域的边框颜色。更改边框的颜色很好,但是线条有点细,所以我只想让彩色线条更粗,以便更明显。
阅读this question 建议使用“lwd”将允许更改厚度。但是,当我尝试时,我要么没有效果,要么线条极粗。
请看下面的例子
library(sf)
library(ggplot)
library(dplyr)
nc <- st_read(system.file("shape/nc.shp", package="sf")) %>%
mutate(type= case_when(
BIR74>16000 ~"High",
TRUE ~"Low"
) %>% factor(levels = c("Low", "High"))) #the levels are ordered to avoid the grey lines overwriting the red ones
nc %>%
ggplot(.) +
geom_sf(aes(fill = BIR74, colour = type)) + #does the job but the coloured borders are quite thing
scale_color_manual(values = c( "#666666","#F8766D"))
nc %>%
ggplot(.) +
geom_sf(aes(fill = BIR74, colour = type,
lwd = ifelse(type =="High", 1, 0.5)) #The values can be anything and it still looks rubbish
) +
scale_color_manual(values = c( "#666666","#F8766D"))
我怎样才能只获得 x% 厚这样的明显厚度?理想情况下,只会更改目标边缘。
【问题讨论】:
-
不确定
lwd来自哪里。对于ggplot,这将是size,然后您可能需要使用手动或其他类型的刻度设置scale_size_*。你不能在aes中设置你想要的值,你用一个比例来设置它们 -
我使用了 lwd,就像他们在链接示例中使用的那样。我尝试了尺寸,但最终还是遇到了同样的问题。你能举一个例子,其中一组边可以控制地大于另一边吗,我不太明白你的评论。
-
你可以把
size = type == "High"放在aes里面。然后将有一种尺寸为真,一种尺寸为假。然后添加scale_size_manual(或_discrete)并在那里设置值。您无法在aes中设置您想要的确切大小(或任何其他美学)。