我想做一个空间情节。我做了情节。我使用不同的颜色来识别不同的值。但是,我想要一种颜色的不同色调。有没有办法根据较高到较低的值使用相同颜色的不同色调绘制相同的图?
library(maps)
C <-88
A <- c(6.79,10.64,11.06,11.59,2.46,10.64,3.22,6.79,6.79,
11.06, 4.82,4.82,6.79,6.79,11.06,3.22,8.12,11.59,
4.82,10.64,8.12,10.64,8.12,8.12,8.12,10.64,2.46,
11.59,4.82,3.22,6.79,10.64,8.12,3.22,10.64,6.79,
2.46,11.06,10.64,2.46,3.22,8.12,11.59,2.46,8.12,
8.12,11.59,10.64,8.12,11.06,8.12,11.06,2.46,10.64,
4.82,3.22,4.82,3.22,8.12,3.22,3.22,10.64,10.64,2.46,
8.12,2.46,11.06,4.82,10.64,11.06,2.46,10.64,2.46,
10.64,4.82,11.06,11.06,11.06, 11.06,8.12, 10.64,2.46,
6.79, 3.22, 11.06, 10.64,10.64,8.12)
A.color <- array(NA,C)
for (i in 1:C) {
if(A[i] == 10.64) A.color[i] <- c("red")
if(A[i] == 11.59) A.color[i] <- c("blue")
if(A[i] == 4.82) A.color[i] <- c("green")
if(A[i] == 8.12) A.color[i] <- c("purple")
if(A[i] == 11.06) A.color[i] <- c("magenta")
if(A[i] == 6.79) A.color[i] <- c("black")
if(A[i] == 2.46) A.color[i] <- c("yellow")
if(A[i] == 3.22) A.color[i] <- c("violet")
}
map("county", "ohio", fill = TRUE, col=A.color[],
border=c(0,0),mar=c(0,0,0,0),main="Undertriage")
title("Undertriage plot by region")
legend("bottomright",legend=c("UT-18.12 %","UT-19.75 %", "UT-8.21 %","UT- 13.84 %","UT-18.85 %", "UT-11.56 %", "UT-4.20 %","UT-5.48 %"),
fill=c("red","blue","green","purple","magenta","black","yellow","violet"),
[![enter image description here][1]][1]bty="n", cex=1.0, horiz=F)
答案 0 :(得分:3)
您始终可以使用rgb()
生成颜色:
A.color <- rgb(1, 0, 0, alpha = (A + 0.5) / (max(A) + 0.5) )
map("county", "ohio", fill = TRUE, col=A.color,
border=c(0,0),mar=c(0,0,0,0),main="Undertriage")
title("Undertriage plot by region")
A.color <- rgb(1.2*max(A) - A, 0, 0, maxColorValue = max(A))
map("county", "ohio", fill = TRUE, col=A.color,
border=c(0,0),mar=c(0,0,0,0),main="Undertriage")
title("Undertriage plot by region")
或者看看?heat.colors
:
A.color <- heat.colors(length(unique(A)))
A.color <- A.color[c(factor(A))]
map("county", "ohio", fill = TRUE, col=A.color,
border=c(0,0),mar=c(0,0,0,0),main="Undertriage")
title("Undertriage plot by region")