我正在尝试绘制此光栅文件的图像。图例的颜色是这样的:红色的低值和绿色的高值。
但通常红色与高值相关联。这就是为什么我用rev
来反转图例颜色的原因。但是我得到了不同的东西。是否有另一种功能可以反转图例的颜色并保持颜色不变。
require(raster)
require(fields)
r = raster(y)
extent(r) = extent(c(xmn=-180,xmx=180,ymn=-90,ymx=90))
plot(r, col = rainbow(20, s = 1, v = 1, start = 0,
end = 1),lab.breaks=seq(0,0.6,0.05),
breaks=seq(0,0.6,0.05), zlim=c(0.0,0.6),horizontal = TRUE,
xlab="Longitude", ylab="Latitude",legend.shrink = 0.9,
legend.width = 1.2)
然后我用这个给了我:
plot(r, col = rev(rainbow(20, s = 1, v = 1, start = 0, end = 1)),
lab.breaks=seq(0,0.6,0.05),breaks=seq(0,0.6,0.05),
zlim=c(0.0,0.6),horizontal = TRUE, xlab="Longitude",
ylab="Latitude",legend.shrink = 0.9,legend.width = 1.2)
答案 0 :(得分:4)
显然你没有检查颜色。
> length(rainbow(20, s = 1, v = 1, start = 0, end = 1))
[1] 20
但并非所有20个都被使用,你只使用其中的12个,所以:
plot(r, col = rev(rainbow(20, s = 1, v = 1, start = 0, end = 1)[1:12]),
lab.breaks=seq(0,0.6,0.05),breaks=seq(0,0.6,0.05),
zlim=c(0.0,0.6),horizontal = TRUE, xlab="Longitude",
ylab="Latitude",legend.shrink = 0.9,legend.width = 1.2)
应该给你想要的情节。毕竟,你有13个休息值,所以只有12个类别。这意味着你可以做到:
plot(r, col = rev(rainbow(12, s = 1, v = 1, start = 0, end = 1)),
lab.breaks=seq(0,0.6,0.05),breaks=seq(0,0.6,0.05),
zlim=c(0.0,0.6),horizontal = TRUE, xlab="Longitude",
ylab="Latitude",legend.shrink = 0.9,legend.width = 1.2)