Filled outline chart with R / ggplot / ggmap

I am having trouble plotting a filled outline on top of a map with ggmap / ggplot2 in R.

My data is regular lat / lon coordinates with a z value indicating rainfall

> head( flood )
   lat       lon         rain
1 22.51916 -105.9318 1.486188e-05
2 22.59956 -105.9318 1.735962e-05
3 22.67996 -105.9318 2.024598e-05
4 22.76037 -105.9318 2.357599e-05
5 22.84077 -105.9318 2.741153e-05
6 22.92117 -105.9318 3.182212e-05

After receiving the basemap with ggmap, I try to overlap the filled rain paths

map = ggmap( baseMap ) + 
    geom_contour( data = flood, aes( x = lon, y = lat, z = rain ) ) +
    scale_fill_continuous( name = "Rainfall (inches)", low = "yellow", high = "red" ) 

It gives me an error

Error in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0

If i do

map = ggmap( baseMap ) + 
    geom_contour( data = flood, aes( x = lon, y = lat, z = rain, fill = ..level.. ) ) +
    scale_fill_continuous( name = "Rainfall (inches)", low = "yellow", high = "red" ) 

I get this plot without actually filling. enter image description here

I tried to follow this post and this post , but I can’t get it right. I don't know much about ggplot / R, but so far I have been able to stumble about it. What does level..level mean?

I think this post may be related, but I cannot generalize the fix for working with contour graphs.

+4
1

( ?).

, :

## not tested..
map = ggmap( baseMap ) + 
    stat_contour( data = flood, geom="polygon", 
                  aes( x = lon, y = lat, z = rain, fill = ..level.. ) ) +
    scale_fill_continuous( name = "Rainfall (inches)", low = "yellow", high = "red" ) 

, geom_contour fill=.... stat_contour(...) geom="polygon" ( "" ).

+6

All Articles