我想知道在R中的3D直方图中是否可以为不同的范围设置不同的颜色。
例如,ı有一张桌子,并且我想用黄色着色相同的范围。 (表[1,1],表[2,2],表[3,3] ...表[12,12] =颜色“黄色”;表[1,2],表[1,3],表[2,3],表[2,4] .... =颜色“绿色”;表[2,1],表[3,1],表[8,5] .... =颜色“红色”。 我怎样才能做到这一点?
我的表数据;
A B C D E F G H I J K L
A 2 7660 1868 673 138 83 13 0 0 0 0 0
B 34 61426 21333 7849 2039 1204 150 3 1 0 1 0
C 8 23539 16409 9646 2309 2088 193 6 2 2 0 0
D 3 12209 12748 12516 3943 4342 547 12 1 1 1 0
E 0 1848 2957 5656 3402 6712 1500 31 0 1 1 0
F 0 3 24 521 637 1798 614 9 2 0 1 0
G 0 0 0 828 1284 4496 2142 44 3 1 1 0
H 0 0 0 195 457 2097 1416 65 0 0 1 1
I 0 0 0 0 161 1327 1355 98 8 3 1 0
J 0 0 0 0 52 559 693 69 8 0 0 1
K 0 0 0 0 40 431 669 97 11 5 0 1
L 0 0 0 0 0 0 0 0 0 0 0 0
hist3D (x = 1:12, y = 1:12, z = table1,bty = "g", phi = 20,
theta = -60,xlab = "Income", ylab = "ModelIncome", zlab = "Counts",
main = "Income&ModelIncome",col = "#0072B2",border = "black",
shade = 0.8,ticktype = "detailed", space = 0.15, d = 2, cex.axis = 1e-9)
答案 0 :(得分:0)
以下是按表索引调整颜色的方法:
table1 <- read.table(header=T, text=" A B C D E F G H I J K L
A 2 7660 1868 673 138 83 13 0 0 0 0 0
B 34 61426 21333 7849 2039 1204 150 3 1 0 1 0
C 8 23539 16409 9646 2309 2088 193 6 2 2 0 0
D 3 12209 12748 12516 3943 4342 547 12 1 1 1 0
E 0 1848 2957 5656 3402 6712 1500 31 0 1 1 0
F 0 3 24 521 637 1798 614 9 2 0 1 0
G 0 0 0 828 1284 4496 2142 44 3 1 1 0
H 0 0 0 195 457 2097 1416 65 0 0 1 1
I 0 0 0 0 161 1327 1355 98 8 3 1 0
J 0 0 0 0 52 559 693 69 8 0 0 1
K 0 0 0 0 40 431 669 97 11 5 0 1
L 0 0 0 0 0 0 0 0 0 0 0 0")
table1 <- as.matrix(table1)
library(plot3D)
colvar <- structure(rep(NA, prod(dim(table1))), .Dim =dim(table1), .Dimnames = dimnames(table1))
diag(colvar) <- 1
colvar[2, ] <- 2
colvar[, 3] <- 3
hist3D (x = 1:12, y = 1:12, z = table1,bty = "g", phi = 20,
theta = -60,xlab = "Income", ylab = "ModelIncome", zlab = "Counts",
main = "Income&ModelIncome",col = c("blue", "yellow", "red"),border = "black",
shade = 0.8,ticktype = "detailed", space = 0.15, d = 2, cex.axis = 1e-9, colvar = colvar)