I'm looking to create a heat map with a little more control over the color scale, specifically I want to have bins for ranges of values that will correspond to a specific color.
Below I provide some sample code to generate some data and make a plot. The issue seems to be how it maps the colors to the breaks, it is not a 1:1 correspondence, when I add more percentiles to the breaks it seems to stretch the colors.
It does not appear to be a large issue here, but when I apply this to the entire US data set I'm working with the color scheme really breaks down.
library(usmap)
library(ggplot2)
fips <- seq(45001,45091,2)
value <- rnorm(length(fips),3000,10000)
data <- data.frame(fips,value)
data$value[data$value<0]=0
plot_usmap(regions='counties',data=data,values="value",include="SC") +
scale_fill_stepsn(breaks=c(as.numeric(quantile(data$value,seq(.25,1,.25)))),
colors=c("blue","green","yellow","red"))
plot_usmap(regions='counties',data=data,values="value",include="SC") +
scale_fill_stepsn(breaks=c(as.numeric(quantile(data$value,seq(0,1,.1)))),
colors=c("blue","green","yellow","red"))
#data not provided for this bit
plot_usmap(regions='counties',data=datar,values="1969",exclude=c("AK","HI")) +
scale_fill_stepsn(breaks=c(as.numeric(quantile(datar$`1969`,seq(0,1,.1)))),
colours=c("blue","green","yellow","red"))