I am trying to plot gridded data and over this plot country boundaries. I get the boundaries form maps package. My code start like this:
graf <- ggplot(data=my_data,aes(x=lon,y=lat,z=med_pos,fill=med_pos))
graf <- graf + + scale_fill_gradient2(low='blue',mid='green',high='red', na.value = 'black')
graf <- graf + geom_tile()
This function well and plot the data as "filled contour". When I try to put as polygon the countries boundaries my code crash. This is the way I do it:
map_data <- map_data('world2')
graf <- graf + geom_polygon(data=map_data,aes(x=long, y = lat, group = group),color='black',fill=NA)
But if I run this last piece alone, it works. Do someone know what is the problem ?
As bonus question, does anyone know how to settle in scale_fill_gradient min and max value ?
Note, my_data is a data.frame with 3 columns, lat , lon and med_pos. These have the coordinates and the value I want to plot.