2016-01-13 58 views
0

enter image description here如何根据密度绘图

我想做一个空间图。我做了情节。我用不同的颜色来识别不同的值。但是,我想要一种颜色的不同色调。是否有任何方法根据较高到较低的值使用相同颜色的不同阴影绘制同一个阴谋?

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) 

回答

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") 

enter image description here

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") 

enter image description here

或者,也许看看?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") 

enter image description here

+0

非常感谢。但我想要不同程度的相同颜色,随着密度的降低,这些颜色将呈现深红色以获得更高的密度,并显示更浅的红色。它会显示一侧显示颜色分布的栏。 – Benzamin

+0

你能告诉我如何在这里添加图例吗? @ J.R – Benzamin

+0

是的,如果您提供有关传说与“A”相关的数据,这不是问题,因此我们不需要像您那样手动执行。然后我们首先对图例和颜色进行排序。 –