【发布时间】:2021-04-04 16:23:17
【问题描述】:
我正在绘制一个 sf 对象(多面体)。根据cand_dummy 列中每个观察值的值,它的几何图形填充了颜色。然而,我试图改变这个情节中的很多东西,但要么我得到了带有颜色的几何图形,但我不能改变颜色,就像这样:
library(ggplot2)
ggplot(data = dta_plot) +
geom_sf(data = dta_plot, aes(fill = cand_dummy))+
theme_map()+
coord_sf(expand = FALSE)+
theme(legend.position="top")+
theme(legend.position="top")+
scale_fill_discrete(name = "Cand", labels = c("No", "Yes"))+
scale_fill_manual(values = c("white", "green4"))
这将为cand_dummy 的不同值打印不同的颜色,但不是我在scale_fill_manual 上设置的颜色。
或者,我在aes 中将fill 更改为colour 并执行以下操作:
ggplot(data = dta_plot) +
geom_sf(data = dta_plot, aes(colour = cand_dummy))+
theme_map()+
coord_sf(expand = FALSE)+
theme(legend.position="top")+
theme(legend.position="top")+
scale_fill_discrete(name = "Cand", labels = c("No", "Yes"))+
scale_fill_manual(values = c("white", "green4"))
但是现在我用这些颜色获得了每个几何图形的边界/边界,而几何图形本身被着色为灰色。所以我找不到获得我想要的东西的方法。 任何的想法? 谢谢!
【问题讨论】: