title: Plotting a grid data on a map using a shapefile with ggplot in R
body: <p>I want to plot grid data on top of a world map using ggplot.</p>
  
  <p>This is what I've tried following this post: <a href="https://stackoverflow.com/questions/11081707/r-plot-grid-value-on-maps">R plot grid value on maps</a>, but I got an error.</p>
  
  <p>The data:</p>
  
  <pre><code>require(maptools)
  nasafile &lt;- "http://eosweb.larc.nasa.gov/sse/global/text/global_radiation"
  nasa &lt;- read.table(file=nasafile, skip=13, header=TRUE)
  </code></pre>
  
  <p>Then, I loaded a shapefile downloaded from here: <a href="http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_land.zip" rel="nofollow noreferrer">http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_land.zip</a></p>
  
  <pre><code>shapef &lt;- readShapeLines(fn = "shapefiles/ne_110m_land.shp")
  </code></pre>
  
  <p>Because I want to use the <code>geom_scatterpie</code> function later I converted the <code>Ann</code> values, which I want to plot, into factors and made a palette. </p>
  
  <pre><code>nasa$Annf &lt;- as.factor(as.character(nasa$Ann))
  mypalette &lt;- colorRampPalette(brewer.pal(9,"YlOrRd"))(533)
  </code></pre>
  
  <p>Then I plotted the data using ggplot:</p>
  
  <pre><code>ggplot(aes(y = Lat , x = Lon), data = nasa )+
    geom_tile(aes(fill=Annf)) +
    guides(fill=FALSE) +
    geom_path(data = shapef) +
    scale_fill_manual(values = mypalette) +
    theme_void() +
    coord_equal()
  </code></pre>
  
  <p>But I get this error:
  <code>Error in eval(expr, envir, enclos) : object 'Lon' not found</code></p>
  
  <p>Even though the <code>Lon</code> column is present in my dataframe:</p>
  
  <pre><code>head(nasa)
    Lat  Lon  Jan  Feb  Mar Apr May Jun Jul Aug Sep  Oct  Nov   Dec  Ann Annf
  1 -90 -180 9.63 5.28 0.75   0   0   0   0   0 0.1 3.24 8.28 10.97 3.19 3.19
  2 -90 -179 9.63 5.28 0.75   0   0   0   0   0 0.1 3.24 8.28 10.97 3.19 3.19
  3 -90 -178 9.63 5.28 0.75   0   0   0   0   0 0.1 3.24 8.28 10.97 3.19 3.19
  4 -90 -177 9.63 5.28 0.75   0   0   0   0   0 0.1 3.24 8.28 10.97 3.19 3.19
  5 -90 -176 9.63 5.28 0.75   0   0   0   0   0 0.1 3.24 8.28 10.97 3.19 3.19
  6 -90 -175 9.63 5.28 0.75   0   0   0   0   0 0.1 3.24 8.28 10.97 3.19 3.19
  </code></pre>
  
  <p>My desired output, would be to have the <code>Annf</code> values plotted on top of the map defined by the shapefile, which is the surface of the landmasses only.</p>