【发布时间】:2021-02-22 00:08:51
【问题描述】:
大家好! 我真的需要一些帮助才能在连续地图上创建离散图例。
但是,我想要的是一个分类图例,根据图例中的每个类别从地图中获取连续值,旨在清楚地表明算法预测的一致性,没有连续的比例。
图 2 你看到了完美的地图,但我想用 ggplot2 来制作它:Here I can clearly indicate in the discrete legend the colors accordingly to the 4 statistical algos.
对于第二张地图,我使用了以下代码:
breakpoints <- c(-125,125,375,625,875,1125)
colors <- c(grey(seq(0.9,0.7,-0.2)),gcolors(3))
a.arg <- list(at=seq(0,1000,length.out=5), labels=c("0","1","2","3","4"),cex.axis=1.5)
l.arg <- list(text="Vote",side=2, line=0.5, cex=1.5)
par(mar=c(0,0,0,r.mar),cex=1.4)
plot(mymap,col=colors,ext=study_area, breaks=breakpoints,
legend.width=1.5,legend.shrink=0.6,legend.mar=7,
axis.args=a.arg,legend.arg=l.arg,
axes=FALSE, box=FALSE, zlim=c(0,1000))
而且效果很好!
但是,在 ggplot2 下我使用的是这段代码:
#Color scales pres
col_scale_var_test_pres <- scale_fill_gradientn(
colours = c(grey(c(0.90,seq(0.9,0.7,-0.2))),gcolors(3)), # colour palete
na.value="transparent",
values=rescale(seq(0,1000),0,1000),
limits=c(0,1000),
breaks= seq(0,1000,by=250), # if one algo predict species occurrence it counts 250, two algos
#(500), ### three (750), four (1000)
labels= c(0,1,2,3,4)
)
b1 <- plot_anomaly_2(r= species_map, label="(b)",title="") + col_scale_var_test_pres
我已经尝试过使用#scale_fill_manual、#scale_fill_gradientn 等,并且还搁置了这个问题(非常相似): R ggplot2 discrete colour palette for gradient map。 但我仍然无法解决这个问题。
任何帮助和建议将不胜感激!
【问题讨论】:
标签: r ggplot2 legend continuous discrete