如何更改从灰色NA颜色为白色的ggplot地区分布图?(How do I change the NA

2019-09-01 03:50发布

我试图创建一个具有默认的颜色从灰色变成白色了美国的地区分布图。

我有记录的48个州18和代码工作颜色的值,但在那里我有没有记录这些州的状态是灰色的。 我想他们是白色的。

如何更改颜色?

library(maps)
library(plyr)
library(ggplot2)
records1<-read.csv('E:/My Documents/records_by_state.csv')
records<-data.frame(state=tolower(rownames(records1)), records1)
head(records)
all_states<-map_data("state")
head(all_states)
record_map<-merge(all_states, records, by.x="region", by.y="state.name")
record_map<-arrange(record_map, group, order)
head(record_map)

p<- ggplot()

p<- p + geom_polygon(data=record_map, aes(x=long, y=lat, group=group,    fill=record_map$Records), colour="black"
         )+ scale_fill_continuous(low="thistle2", high="darkred", guide="colorbar")
P1 <- p + theme_bw() +labs(fill= "Records by State"
                    , title= "By State", x="", y="")
P1 + scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) +  theme(panel.border= element_blank())

Answer 1:

你可以通过改变参数改变NA值(无数据状态)的颜色na.valuescale_fill_continuos()

+scale_fill_continuous(low="thistle2", high="darkred", 
                       guide="colorbar",na.value="white")


文章来源: How do I change the NA color from gray to white in a ggplot choropleth map?