0

I'm trying to include a map of the shoreline, and possibly also the country boundaries, on top of a levelplot with latitude and longitude coordinates.

The code I have so far for the levelplot is:

library(lattice)
library(ncdf4)

ncin <- nc_open("testplot.nc")
tp <- ncvar_get(ncin,"tp")
lon <- ncvar_get(ncin,"longitude")
lat <- ncvar_get(ncin,"latitude")

grid <- expand.grid(lon=lon, lat=lat)

levelplot(tp ~ lon * lat, data=grid)

The image that I get is this:

enter image description here

How can I get include a geographical map to the plot?

Update: I want the slice of the earth between 37°-31°N and 34°-31°E on the plot. Only the shorelines and country borders, so that you are still able to see the colour shading.

Thank you.

AlexLee
  • 429
  • 4
  • 11
  • 1
    Could you add a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). That way you can help others to help you! – dario Feb 19 '20 at 13:41
  • Sorry for the late reply. I can share the file "testplot.nc" to make the code more reproducible. https://drive.google.com/open?id=12x--kd8xaEtKMkStrcgFNfE2F23QwFma – AlexLee Feb 26 '20 at 13:16
  • Never mind. I can't access google storage. But that's not a [minimale reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) anyways. I should not have to have access to your data. You should provide a MRE instead (which, by definition, includes only as little data and code as is necessary to reproduce your problem. Not a single line more). I know that's not always easy and of course you are free to do as you chose. – dario Feb 26 '20 at 13:22
  • Dario, you don't need access to google storage in order download the file. Just press the link and then download the file. That definitely works without a google account. – AlexLee Feb 26 '20 at 14:37
  • Furthermore, I can't just add an entire netCDF file to code. – AlexLee Feb 26 '20 at 14:44
  • 1.You don't provide a MRE. 2.I already told you that I can't access google storage?! I also explained that I shouldn't have to. 3.I took time to try and explain you what an MRE is and why it is useful. But apparently you do not care - I have nothing else to say to help you. As I already said: You are free to do as you chose. But so do I. – dario Feb 26 '20 at 14:53

0 Answers0