我有一个能够使用Prioritizr解决的空间问题的列表,但我不能绘制解决方案。
以下是问题列表:
p <- readRDS("Input/Problems/01b_ProblemsIUCNLong.rds")
这是我用来解决这个问题的代码:
s2 <- lapply(readRDS("Input/Problems/01b_ProblemsIUCNLong.rds"), function(x) {
f <- solve(x, force= TRUE) %>%
st_as_sf(sf_column_name = "geometry")
ff <- f %>% mutate(Selected_Area = round(nrow(f[f$solution_1 == 1,])/nrow(f), 1)*100)
} )
然而,我似乎不能绘制它并继续得到相同的错误:
IUCNonlyTarget10_withLP_plot <- ggplot() +
+ geom_sf(data = s2[[1]], aes(fill = as.factor(solution_1), color = NA, size = 0.02, show.legend = FALSE)) +
+ scale_fill_manual(name = "Solution",
+ values = pal_rich,
+ labels = solution) +
+ geom_sf(data = world_sf, size = 0.05, fill = "grey20") +
+ coord_sf(xlim = c(st_bbox(Bndry)$xmin, st_bbox(Bndry)$xmax),
+ ylim = c(st_bbox(Bndry)$ymin, st_bbox(Bndry)$ymax),
+ expand = TRUE) +
+ ggtitle("Target 10%") +
+ theme_bw() +
+ ggsave("Output/Figs/IUCNonlyTarget10_withLP_06.pdf", width = 20, height = 10, dpi = 300) +
+ ggsave("Output/Figs/IUCNonlyTarget10_withLP_06.png", width = 20, height = 10, dpi = 300)
Error: Must request at least one colour from a hue palette.
In addition: Warning message:
Ignoring unknown aesthetics: show.legend
有没有想过我可以解决这个问题?
我试着删除color = NA
,也试着把它放在aes()
之外,但是我得到了一个空图层……即使我检查了它不是一个空层...
这就是我所得到的
虽然它应该是这样的
有什么建议吗?
发布于 2021-07-04 00:32:57
这是括号里的错位。
IUCNonlyTarget10_withLP_plot <- ggplot() +
+ geom_sf(data = s2[[1]], aes(fill = as.factor(solution_1)), color = NA, size = 0.02, show.legend = FALSE) +
+ scale_fill_manual(name = "Solution",
+ values = pal_rich,
+ labels = solution) +
+ geom_sf(data = world_sf, size = 0.05, fill = "grey20") +
+ coord_sf(xlim = c(st_bbox(Bndry)$xmin, st_bbox(Bndry)$xmax),
+ ylim = c(st_bbox(Bndry)$ymin, st_bbox(Bndry)$ymax),
+ expand = TRUE) +
+ ggtitle("Target 10%") +
+ theme_bw() +
+ ggsave("Output/Figs/IUCNonlyTarget10_withLP_06.pdf", width = 20, height = 10, dpi = 300) +
+ ggsave("Output/Figs/IUCNonlyTarget10_withLP_06.png", width = 20, height = 10, dpi = 300)
https://stackoverflow.com/questions/68228020
复制相似问题