title: R ggplot2 merge with shapefile and csv data to fill polygons - specific
body: <p>I know that this question has been answered <a href="https://stackoverflow.com/questions/19791210/r-ggplot2-merge-with-shapefile-and-csv-data-to-fill-polygons">elsewhere</a> already. I tried to follow the instructions of @jlhoward but obviously my skills are too limited. May I ask again of your help, R community?</p>
  
  <p>Here's what I have:</p>
  
  <p>A shapefile for Switzerland: <a href="http://data.geo.admin.ch/ch.swisstopo-vd.ortschaftenverzeichnis_plz/PLZO_SHP_LV03.zip" rel="nofollow noreferrer">Link</a></p>
  
  <p>And the corresponding CSV-file for the names of municipalities as well as their zip-codes: <a href="http://data.geo.admin.ch/ch.swisstopo-vd.ortschaftenverzeichnis_plz/PLZO_CSV_LV03.zip" rel="nofollow noreferrer">Link</a></p>
  
  <p>Website of data: <a href="http://www.cadastre.ch/internet/cadastre/de/home/products/plz/data.html" rel="nofollow noreferrer">cadastre.ch</a></p>
  
  <p>Additional data on the last popular vote: <a href="http://www.bfs.admin.ch/bfs/portal/de/index/infothek/lexikon/lex/0.Document.176630.xls" rel="nofollow noreferrer">Direct link, excel-file</a></p>
  
  <p>I add a column to the CSV-file (wow.csv) (the data I want to illustrate) by merging. The file looks now like this:</p>
  
  <pre><code>Gemeinden   code    Ja.Anteil   Ortschaft       PLZ Zusatzziffer    Kantonskürzel   E   N
  1   Aadorf  4551    78.78638    Aawangen        8522    2           TG            710206    263564
  2   Aadorf  4551    78.78638    Ettenhausen TG  8356    0           TG            710129    259411
  3   Aadorf  4551    78.78638    Aadorf          8355    0           TG            710588    261648
  4   Aadorf  4551    78.78638    Guntershausen   8357    0           TG            711741    258934
  5   Aadorf  4551    78.78638    Wittenwil       9547    0           TG            712002    262572
  </code></pre>
  
  <p>Afterwards I tried to follow the instructions of @jlhoward:</p>
  
  <ol>
  <li>Import temperature data file </li>
  <li>Import polygon shapefile of municipalities </li>
  <li>Convert <code>muni</code> polygons to a data frame for plotting </li>
  <li>Join columns from <code>ch12@data</code> to <code>ch12.df</code></li>
  <li>Join columns from <code>wow</code> to <code>ch12.df</code></li>
  <li>Make the plot</li>
  </ol>
  
  <p>I tried it with the following code:</p>
  
  <pre><code>require("rgdal")
  require("maptools")
  require("ggplot2")
  require("plyr")
  
  # read share data and the file from cadastre.ch (zip-codes)
  asyl &lt;- &lt;- read.csv("~/FS14-1/PLZO_SHP_LV03/Asylgesetz_csv.csv", sep=";")
  mydata1 &lt;- read.table("~/FS14-1/PLZO_SHP_LV03/PLZO_CSV_LV03.csv", sep=";", quote="\"")
  
  #merge the two files
  wow &lt;- merge(x = asyl, y = mydata1, by = "Gemeinden", all = TRUE)
  
  # read municipality polygons
  ch12 &lt;- readOGR(work.dir, layer = "PLZO_PLZ")
  
  # fortify and merge: muni.df is used in ggplot
  ch12@data$id &lt;- rownames(ch12@data)
  ch12.df &lt;- fortify(ch12)
  ch12.df &lt;- join(ch12.df, ch12@data, by="id")
  ch12.df &lt;- merge(ch12.df, wow, by="PLZ", all.x=T, a..ly=F)
  
  #create the map layers
  gp &lt;- ggplot(data=ch12.df, aes(x=long, y=lat, group=group)) + 
        geom_polygon(aes(group = group))+         # draw polygons
        geom_path(color="grey", linestyle=2)+  # draw boundaries
        coord_equal() +
        scale_fill_gradient(low = "#ffffcc", high = "#ff4444", 
                               space = "Lab", na.value = "grey50",
                               guide = "colourbar")+
        labs(title="Zustimmung auf Gemeindelevel")
  gp
  </code></pre>
  
  <p>Well, until the last step, R worked (so far I can tell) but if I try to create the ggplot, I get no an error and R somehow terminates. What I'm trying to achieve is to control the colours (in my case of municipalities) of the polygons depending on data...</p>
  
  <p>Can anyone help me?</p>