我正在绘制一个sf对象(多多边形)。I,其几何形状根据列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"))
但是现在我得到了这些颜色的每个几何体的边界/边框,而几何体本身是灰色的。所以我找不到得到我想要的东西的方法。有什么想法吗?谢谢!
发布于 2021-04-04 16:47:22
我认为问题在于您在代码中同时包含了函数scale_fill_manual和scale_fill_discrete。我相信你应该只有以下功能:
scale_fill_manual(values = c("white", "green4"), name = "Cand", labels = c("No", "Yes"))
如果这对你的第一个代码块不起作用,请告诉我。
https://stackoverflow.com/questions/66943405
复制