1

I have eleven county scale shapefiles named "df_1_imid_soy_2004.shp" for all years from 2004 to 2014 containing rows for every county in three states (Dakotas and Minnesota)

I also have eleven csv files containing a "st_cnty" unique key that is used to merge to its corresponding shapefile. There is also a column called "g_per_acre_soy" that is the continuous variable I want to plot with a yellow to red color map to illustrate the quantity.

library(ggmap)
library(rgdal)
library(rgeos)
library(maptools)
library(dplyr)
library(tidyr)
require(sp)
require(RColorBrewer)

par(mfrow=c(4,3),mar=c(0.6,0.6,0.6,0.6), oma=c(1,1,1,1))

yearList = c(2004:2014)
for (year in yearList){
  #shape is original shapefile and table is csv to join
  shape = readOGR(".",print(paste0("df_1_imid_corn_",year)))
  table = read.csv(print(paste0("df_1_imid_corn_",year,".csv")))
  shape@data$order <- 1:nrow(shape@data)
  shape@data <- merge(shape@data, table, by.x = "st_cnty",by.y="st_cnty",all.x=T)

  #new shapefile to remove nas because not all rows join 
  shape2 <- shape[!is.na(shape@data$g_per_acre_corn),]
  shape2@data$order <- 1:nrow(shape2@data)

  #the variable being plotted has a large variance between counties.
  #here I attempt using breakpoints and cut and assign each row a color
  breakpoints <- seq(0,1,by=0.01)
  myPaletteBlue = brewer.pal(1,'RdYlGn')
  createColors  = colorRampPalette(myPaletteBlue)
  myColorsBlue  <- createColors(length(breakpoints)-1)  
  numberColors = length(unique(myColorsBlue))
  shape2@data$g_per_acre_corn_cat = cut(shape2@data$g_per_acre_corn,breakpoints)
  shape2@data = shape2@data[order(shape2@data$g_per_acre_corn),]
  colorOfCats  = data.frame(g_corn_cat=levels(shape2@data$g_per_acre_corn_cat),colors=unique(myColorsBlue))
  shape2@data = merge(shape2@data,colorOfCats)

  #then make the plots
  plot(shape2,col=as.character(shape2@data$colors))
  plot(shape, add=T)
  title(main=year,add=T)
}

The merging and plotting works, but I'm not sure how best to plot the column with high variance and significantly increases from year to year. For example, the dependent variable in 2004 ranges from (0.1-250,n=110,mean=2) but in 2014 ranges from (0.9-500,n=130, mean=50).

So I would like to plot all years on the same figure with ONE INDIVIDUAL SCALE to visualize annual changes.

1) What is the best way to keep the same scale for all years, but also have enough variation with colors to visualize inter-county changes within the same year?

Below, red=data, white=NA (not joined)

output

closed as too broad by Vince, whyzar, Andre Silva, mgri, John Powell Apr 3 '17 at 8:59

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Even though you've been here for a while, you still haven't taken the tour. It states that each Question should have exactly one question. Please edit your question to focus on your most important issue. – Vince Apr 3 '17 at 1:22