title: Choropleth map with R using shp file
body: <p>Hello stackoverflow community!</p>
  
  <p>Could someone kindly please assist me as I am having some difficulties with creating a choropleth map in R. As of now, I have assigned LL information to my points of interest, and I now want to create a choropleth map using the "cans" variable in the dataset (data.csv) by high school district area (highdist_n83.shp.zip). What I would like to please know is how to properly fill the map with the sum of cans per district area. I have provided code, which pulls a sample datafile from dropbox and the shape file I would like to use.</p>
  
  <p><strong>EDIT</strong>
  Sorry, I forgot to add that when I plot just the shape file, I am able to see it rendered via ggplot. However, when I try to "fill" the districts using the number of "cans" variable, R hangs for awhile before rendering what appears to be a mass of lines over the original shape. I wonder if the error is due to the following possible reasons</p>
  
  <ol>
  <li>the shape file is not good</li>
  <li>there may be an issue with how I am merging the data frame and the shape file as I've noticed additional rows are added to the merged file</li>
  <li>there are multiple schools in an area, which I haven't combined when using ddply.</li>
  </ol>
  
  <p>Thank you for your time!</p>
  
  <pre><code>###load R scripts from dropbox
  dropbox.eval &lt;- function(x, noeval=F) {
  require(RCurl)
  intext &lt;- getURL(paste0("https://dl.dropboxusercontent.com/",x), ssl.verifypeer = FALSE)
  intext &lt;- gsub("\r","", intext)
  if (!noeval) eval(parse(text = intext), envir= .GlobalEnv)
  return(intext)
  }
  
  ##pull scripts from dropbox 
  dropbox.eval("s/wgb3vtd9qfc9br9/pkg.load.r")    
  dropbox.eval("s/tf4ni48hf6oh2ou/dropbox.r")
  
  ##load packages
  pkg.load(c(ggplot2,plyr,gdata,sp,maptools,rgdal,reshape2))
  
  ###setup data frames
  dl_from_dropbox("data.csv","dx3qrcexmi9kagx")
      data&lt;-read.csv(file='data.csv',header=TRUE)
  
  ###prepare GIS shape and data for plotting
  dropbox.eval("s/y2jsx3dditjucxu/dlshape.r")     
  temp &lt;- tempfile()
  dlshape(shploc="http://files.hawaii.gov/dbedt/op/gis/data/highdist_n83.shp.zip", temp)
  shape&lt;- readOGR(".","highdist_n83") #HDOE high school districts  
  shape@proj4string 
  
  shape2&lt;- spTransform(shape, CRS("+proj=longlat +datum=NAD83"))
  
  data.2&lt;-ddply(data, .(year, schoolcode, longitude, latitude,NAME,HDist,SDist), summarise,
          total = sum(total),
          cans= sum(cans))
  
  coordinates(data.2) &lt;-~longitude + latitude
  shape2.df&lt;-fortify(shape2)
  mshape2.df&lt;- merge(shape2.df,shape2@data, by.x="id", by.y="ID",all=TRUE)
  
  newdata &lt;- merge(mshape2.df,data.2, by.x="NAME", by.y="NAME", all=TRUE)
  newdata  &lt;- newdata [order(newdata $order),]
  
  ###choropleth map: 
  mapPlot &lt;- ggplot(newdata,aes(x=long, y=lat,drop=FALSE)) +
  geom_polygon(aes(fill=cans, drop=FALSE), colour = "black", lwd = 1/9,na.rm=FALSE)
  + ggtitle("Total of Cans Across State")
  print(mapPlot)
  </code></pre>