我尝试使用ggplot映射过去一年与AI相关的职位,但是我需要反转默认的配色方案,以便将其从浅蓝色(#52ABF0)变为深蓝色(#142E47)。另外,我有一些离群的邮政编码(一个区域为856个职位发布,另一区域为516个职位发布)。大多数职位发布范围为0-300。因此,我还需要将标记更改为0-100、100-200、200-300和300+,而不是均匀隔开。
我尝试使用scale_fill_gradientn和scale_fill_gradient2,但是由于某些原因,当我尝试绘制图形时,ggplot会跳过这些命令。
[install.packages('zipcode')
library(zipcode)
library(tidyverse)
install.packages('maps')
library(maps)
install.packages('viridis')
library(viridis)
install.packages('ggthemes')
library(ggthemes)
devtools::install_github("hrbrmstr/albersusa")
install.packages('albersusa')
library(albersusa)
fm<-Export <- read.csv("ai_job_postings.csv", header=FALSE)
colnames(fm) <- colnames(Export) <- c("job_id", "post_date", "fill_date", "time_to_fill", "company", "vertical", "location", "salary",
"city", "state", "zip", "county", "latitude", "longitude", "region_state")
fm.zip<-aggregate(data.frame(count=fm$job_id),list(zip=fm$zip,county=fm$county),length)
fm<- merge(fm.zip, zipcode, by='zip')
us<-map_data('state')
ggplot(fm,aes(longitude,latitude)) +
geom_polygon(data=us,aes(x=long,y=lat,group=group),color='gray',fill=NA,alpha=.35)+
geom_point(aes(color = count),size=2.5,alpha=.25) +
xlim(-125,-65)+ylim(20,50) +
theme(panel.grid.major = element_blank(),
panel.background = element_blank(),
panel.grid.minor = element_blank(),
axis.ticks.y=element_blank(),
axis.ticks.x=element_blank(),
axis.text.x = element_blank(),
axis.title=element_blank(),
axis.text = element_blank(),
legend.title=element_text(size=25),
legend.text=element_text(size=14),
plot.caption = element_text(size=12, hjust = 1.3)) +
scale_fill_gradient2(low = "#52ABF0", mid = "#3874A5", high = "#142E47", midpoint = 200, guide="colorbar", limits=c(0,900)) +
labs(color="AI Postings", caption=paste0(sum(fm$count), " AI Job Postings Nationwide June 2018 - June 2019"))]