levelplot 中的 3 个不同颜色区域
3 different colour regions in levelplot
尝试绘制此矩阵,使负值为红色,0 为蓝色,正值为绿色。
m <- matrix(c(0,0,-1,-2,0,0,1,0,1,3,3,3,-3,0,0,2),nrow = 4)
levelplot(m,at=c(-3,0,3),col.regions=c("red","blue","green"),xlab = xlab.a, ylab="", colorkey = FALSE, panel = function(...) {
panel.fill(col = "blue")
panel.levelplot(...)
})
m <- matrix(c(0,0,-1,-2,0,0,1,0,1,3,3,3,-3,0,0,2),nrow = 4)
levelplot(m,at=c(-3,-1,0,3),col.regions=c("red","blue","green"), xlab = "", ylab="", colorkey = FALSE, panel = function(...) {
panel.fill(col = "blue")
panel.levelplot(...)
})
这是使用布尔比较的另一种通用方法:
levelplot((m>=0) + (m > 0),at=c(-0.1, 0:2),col.regions=c("red","blue","green"), xlab = "", ylab="", colorkey = FALSE, panel = function(...) {
panel.fill(col = "blue")
panel.levelplot(...)
})
尝试绘制此矩阵,使负值为红色,0 为蓝色,正值为绿色。
m <- matrix(c(0,0,-1,-2,0,0,1,0,1,3,3,3,-3,0,0,2),nrow = 4)
levelplot(m,at=c(-3,0,3),col.regions=c("red","blue","green"),xlab = xlab.a, ylab="", colorkey = FALSE, panel = function(...) {
panel.fill(col = "blue")
panel.levelplot(...)
})
m <- matrix(c(0,0,-1,-2,0,0,1,0,1,3,3,3,-3,0,0,2),nrow = 4)
levelplot(m,at=c(-3,-1,0,3),col.regions=c("red","blue","green"), xlab = "", ylab="", colorkey = FALSE, panel = function(...) {
panel.fill(col = "blue")
panel.levelplot(...)
})
这是使用布尔比较的另一种通用方法:
levelplot((m>=0) + (m > 0),at=c(-0.1, 0:2),col.regions=c("red","blue","green"), xlab = "", ylab="", colorkey = FALSE, panel = function(...) {
panel.fill(col = "blue")
panel.levelplot(...)
})